├── tests ├── 3rdparty │ ├── CMakeLists.txt │ ├── tinycthread │ │ ├── CMakeLists.txt │ │ └── README.txt │ └── glfw │ │ ├── src │ │ ├── glfwConfigVersion.cmake.in │ │ ├── glfw3.pc.in │ │ ├── glfwConfig.cmake.in │ │ ├── time.c │ │ ├── config.h │ │ ├── clipboard.c │ │ ├── cocoa_time.c │ │ ├── nsgl_platform.h │ │ ├── cocoa_clipboard.m │ │ ├── joystick.c │ │ ├── egl_platform.h │ │ ├── win32_gamma.c │ │ ├── win32_time.c │ │ ├── x11_time.c │ │ ├── cocoa_gamma.c │ │ ├── CMakeLists.txt │ │ ├── config.h.in │ │ ├── wgl_platform.h │ │ ├── gamma.c │ │ ├── win32_clipboard.c │ │ ├── cocoa_init.m │ │ ├── cocoa_platform.h │ │ ├── x11_gamma.c │ │ ├── glx_platform.h │ │ ├── win32_joystick.c │ │ ├── init.c │ │ ├── win32_init.c │ │ ├── x11_joystick.c │ │ ├── x11_platform.h │ │ ├── win32_platform.h │ │ ├── win32_monitor.c │ │ ├── nsgl_context.m │ │ └── monitor.c │ │ ├── COPYING.txt │ │ ├── CMakeLists.txt │ │ ├── deps │ │ ├── getopt.h │ │ └── getopt.c │ │ └── include │ │ └── GLFW │ │ └── glfw3native.h ├── dataset │ └── lena.tga ├── raster │ ├── CMakeLists.txt │ └── main.c ├── voronoi │ ├── CMakeLists.txt │ └── main.c ├── raytracing │ ├── CMakeLists.txt │ └── main.c └── vorogen │ └── CMakeLists.txt ├── include ├── m_math.h ├── m_raster.h ├── m_path_finding.h └── m_dist.h ├── CMake └── OutOfSourceBuild.cmake ├── .gitignore ├── LICENSE ├── CMakeLists.txt └── README.md /tests/3rdparty/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_SUBDIRECTORY(tinycthread) 2 | ADD_SUBDIRECTORY(glfw) -------------------------------------------------------------------------------- /include/m_math.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anael-seghezzi/Maratis-Tiny-C-library/HEAD/include/m_math.h -------------------------------------------------------------------------------- /include/m_raster.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anael-seghezzi/Maratis-Tiny-C-library/HEAD/include/m_raster.h -------------------------------------------------------------------------------- /tests/dataset/lena.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anael-seghezzi/Maratis-Tiny-C-library/HEAD/tests/dataset/lena.tga -------------------------------------------------------------------------------- /CMake/OutOfSourceBuild.cmake: -------------------------------------------------------------------------------- 1 | # Disallow in-source build 2 | STRING(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" BUILDING_IN_SOURCE) 3 | IF(BUILDING_IN_SOURCE) 4 | MESSAGE(FATAL_ERROR "This project requires an out of source build. Please create a separate build directory and run 'cmake [options] ' there.") 5 | ENDIF(BUILDING_IN_SOURCE) 6 | 7 | -------------------------------------------------------------------------------- /tests/3rdparty/tinycthread/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ## Find source and headers 2 | FILE(GLOB HEADERS source/*.h) 3 | FILE(GLOB SOURCES source/*.c*) 4 | 5 | IF(CMAKE_HAS_SORT) 6 | LIST(SORT HEADERS) 7 | LIST(SORT SOURCES) 8 | ENDIF(CMAKE_HAS_SORT) 9 | 10 | ## Build 11 | INCLUDE_DIRECTORIES( 12 | source 13 | ) 14 | 15 | ADD_LIBRARY(tinycthread ${SOURCES} ${HEADERS}) 16 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/src/glfwConfigVersion.cmake.in: -------------------------------------------------------------------------------- 1 | 2 | set(PACKAGE_VERSION "@GLFW_VERSION_FULL@") 3 | 4 | if ("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL "@GLFW_VERSION_MAJOR@") 5 | set(PACKAGE_VERSION_COMPATIBLE TRUE) 6 | if ("${PACKAGE_FIND_VERSION_MINOR}" EQUAL @GLFW_VERSION_MINOR@) 7 | set(PACKAGE_VERSION_EXACT TRUE) 8 | endif() 9 | else() 10 | set(PACKAGE_VERSION_COMPATIBLE FALSE) 11 | endif() 12 | 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.ko 4 | *.obj 5 | *.elf 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Libraries 12 | *.lib 13 | *.a 14 | *.la 15 | *.lo 16 | 17 | # Shared objects (inc. Windows DLLs) 18 | *.dll 19 | *.so 20 | *.so.* 21 | *.dylib 22 | 23 | # Executables 24 | *.exe 25 | *.out 26 | *.app 27 | *.i*86 28 | *.x86_64 29 | *.hex 30 | 31 | # Debug files 32 | *.dSYM/ 33 | 34 | Build 35 | bin 36 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/src/glfw3.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | includedir=${prefix}/include 4 | libdir=${exec_prefix}/lib 5 | 6 | Name: GLFW 7 | Description: A portable library for OpenGL, window and input 8 | Version: @GLFW_VERSION_FULL@ 9 | URL: http://www.glfw.org/ 10 | Requires.private: @GLFW_PKG_DEPS@ 11 | Libs: -L${libdir} -l@GLFW_LIB_NAME@ 12 | Libs.private: @GLFW_PKG_LIBS@ 13 | Cflags: -I${includedir} 14 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/src/glfwConfig.cmake.in: -------------------------------------------------------------------------------- 1 | # - Config file for the glfw package 2 | # It defines the following variables 3 | # GLFW_INCLUDE_DIR, the path where GLFW headers are located 4 | # GLFW_LIBRARY_DIR, folder in which the GLFW library is located 5 | # GLFW_LIBRARY, library to link against to use GLFW 6 | 7 | set(GLFW_INCLUDE_DIR "@CMAKE_INSTALL_PREFIX@/include") 8 | set(GLFW_LIBRARY_DIR "@CMAKE_INSTALL_PREFIX@/lib@LIB_SUFFIX@") 9 | 10 | find_library(GLFW_LIBRARY "@GLFW_LIB_NAME@" HINTS ${GLFW_LIBRARY_DIR}) 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Maratis Tiny C library 2 | 3 | Copyright (c) 2015 Anael Seghezzi 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 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/COPYING.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2002-2006 Marcus Geelnard 2 | Copyright (c) 2006-2010 Camilla Berglund 3 | 4 | This software is provided 'as-is', without any express or implied 5 | warranty. In no event will the authors be held liable for any damages 6 | arising from the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it 10 | freely, subject to the following restrictions: 11 | 12 | 1. The origin of this software must not be misrepresented; you must not 13 | claim that you wrote the original software. If you use this software 14 | in a product, an acknowledgment in the product documentation would 15 | be appreciated but is not required. 16 | 17 | 2. Altered source versions must be plainly marked as such, and must not 18 | be misrepresented as being the original software. 19 | 20 | 3. This notice may not be removed or altered from any source 21 | distribution. 22 | 23 | -------------------------------------------------------------------------------- /tests/raster/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ## Find source and headers 2 | FILE(GLOB HEADERS 3 | *.h 4 | ${MTCL_INCLUDE_DIR}/*.h 5 | ) 6 | FILE(GLOB SOURCES 7 | *.c* 8 | ) 9 | 10 | IF(CMAKE_HAS_SORT) 11 | LIST(SORT HEADERS) 12 | LIST(SORT SOURCES) 13 | ENDIF(CMAKE_HAS_SORT) 14 | 15 | ## Build 16 | INCLUDE_DIRECTORIES( 17 | ## Maratis 18 | ${MTCL_INCLUDE_DIR} 19 | 20 | ## 3rdparty 21 | ${GLFW_INCLUDE_DIR} 22 | ${TINYCTHREAD_INCLUDE_DIR} 23 | ) 24 | 25 | ADD_EXECUTABLE(RasterTest ${SOURCES} ${HEADERS}) 26 | 27 | TARGET_LINK_LIBRARIES(RasterTest 28 | 29 | ## 3rdparty 30 | ${GLFW_LIBRARIES} 31 | ${TINYCTHREAD_LIBRARIES} 32 | 33 | ## System libraries 34 | ${OPENGL_LIBRARIES} 35 | ${PLATFORM_LIBRARIES} 36 | ${OS_SPECIFIC_LIBRARIES} 37 | ) 38 | 39 | ## Install 40 | INSTALL(TARGETS RasterTest DESTINATION ${MTCL_INSTALL_DIR}) 41 | 42 | IF(APPLE) 43 | SET_TARGET_PROPERTIES( 44 | RasterTest 45 | PROPERTIES 46 | BUILD_WITH_INSTALL_RPATH 1 47 | INSTALL_RPATH "@loader_path/" 48 | ) 49 | ENDIF(APPLE) 50 | 51 | IF(UNIX AND NOT APPLE) 52 | SET_TARGET_PROPERTIES( 53 | RasterTest 54 | PROPERTIES 55 | BUILD_WITH_INSTALL_RPATH 1 56 | INSTALL_RPATH "$ORIGIN/" 57 | ) 58 | ENDIF(UNIX AND NOT APPLE) 59 | -------------------------------------------------------------------------------- /tests/voronoi/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ## Find source and headers 2 | FILE(GLOB HEADERS 3 | *.h 4 | ${MTCL_INCLUDE_DIR}/*.h 5 | ) 6 | FILE(GLOB SOURCES 7 | *.c* 8 | ) 9 | 10 | IF(CMAKE_HAS_SORT) 11 | LIST(SORT HEADERS) 12 | LIST(SORT SOURCES) 13 | ENDIF(CMAKE_HAS_SORT) 14 | 15 | ## Build 16 | INCLUDE_DIRECTORIES( 17 | ## Maratis 18 | ${MTCL_INCLUDE_DIR} 19 | 20 | ## 3rdparty 21 | ${GLFW_INCLUDE_DIR} 22 | ${TINYCTHREAD_INCLUDE_DIR} 23 | ) 24 | 25 | ADD_EXECUTABLE(VoronoiTest ${SOURCES} ${HEADERS}) 26 | 27 | TARGET_LINK_LIBRARIES(VoronoiTest 28 | ## 3rdparty 29 | ${GLFW_LIBRARIES} 30 | ${TINYCTHREAD_LIBRARIES} 31 | 32 | ## System libraries 33 | ${OPENGL_LIBRARIES} 34 | ${PLATFORM_LIBRARIES} 35 | ${OS_SPECIFIC_LIBRARIES} 36 | ) 37 | 38 | ## Install 39 | INSTALL(TARGETS VoronoiTest DESTINATION ${MTCL_INSTALL_DIR}) 40 | 41 | IF(APPLE) 42 | SET_TARGET_PROPERTIES( 43 | VoronoiTest 44 | PROPERTIES 45 | BUILD_WITH_INSTALL_RPATH 1 46 | INSTALL_RPATH "@loader_path/" 47 | ) 48 | ENDIF(APPLE) 49 | 50 | IF(UNIX AND NOT APPLE) 51 | SET_TARGET_PROPERTIES( 52 | VoronoiTest 53 | PROPERTIES 54 | BUILD_WITH_INSTALL_RPATH 1 55 | INSTALL_RPATH "$ORIGIN/" 56 | ) 57 | ENDIF(UNIX AND NOT APPLE) 58 | -------------------------------------------------------------------------------- /tests/raytracing/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ## Find source and headers 2 | FILE(GLOB HEADERS 3 | *.h 4 | ${MTCL_INCLUDE_DIR}/*.h 5 | ) 6 | FILE(GLOB SOURCES 7 | *.c* 8 | ) 9 | 10 | IF(CMAKE_HAS_SORT) 11 | LIST(SORT HEADERS) 12 | LIST(SORT SOURCES) 13 | ENDIF(CMAKE_HAS_SORT) 14 | 15 | ## Build 16 | INCLUDE_DIRECTORIES( 17 | ## Maratis 18 | ${MTCL_INCLUDE_DIR} 19 | 20 | ## 3rdparty 21 | ${GLFW_INCLUDE_DIR} 22 | ${TINYCTHREAD_INCLUDE_DIR} 23 | ) 24 | 25 | ADD_EXECUTABLE(RaytracingTest ${SOURCES} ${HEADERS}) 26 | 27 | TARGET_LINK_LIBRARIES(RaytracingTest 28 | ## 3rdparty 29 | ${GLFW_LIBRARIES} 30 | ${TINYCTHREAD_LIBRARIES} 31 | 32 | ## System libraries 33 | ${OPENGL_LIBRARIES} 34 | ${PLATFORM_LIBRARIES} 35 | ${OS_SPECIFIC_LIBRARIES} 36 | ) 37 | 38 | ## Install 39 | INSTALL(TARGETS RaytracingTest DESTINATION ${MTCL_INSTALL_DIR}) 40 | 41 | IF(APPLE) 42 | SET_TARGET_PROPERTIES( 43 | RaytracingTest 44 | PROPERTIES 45 | BUILD_WITH_INSTALL_RPATH 1 46 | INSTALL_RPATH "@loader_path/" 47 | ) 48 | ENDIF(APPLE) 49 | 50 | IF(UNIX AND NOT APPLE) 51 | SET_TARGET_PROPERTIES( 52 | RaytracingTest 53 | PROPERTIES 54 | BUILD_WITH_INSTALL_RPATH 1 55 | INSTALL_RPATH "$ORIGIN/" 56 | ) 57 | ENDIF(UNIX AND NOT APPLE) 58 | -------------------------------------------------------------------------------- /tests/vorogen/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ## Find source and headers 2 | FILE(GLOB HEADERS 3 | *.h 4 | ${MTCL_INCLUDE_DIR}/*.h 5 | ${STB_INCLUDE_DIR}/*.h 6 | ) 7 | FILE(GLOB SOURCES 8 | *.c* 9 | ) 10 | 11 | IF(CMAKE_HAS_SORT) 12 | LIST(SORT HEADERS) 13 | LIST(SORT SOURCES) 14 | ENDIF(CMAKE_HAS_SORT) 15 | 16 | ## Build 17 | INCLUDE_DIRECTORIES( 18 | ## Maratis 19 | ${MTCL_INCLUDE_DIR} 20 | 21 | ## 3rdparty 22 | ${GLFW_INCLUDE_DIR} 23 | ${TINYCTHREAD_INCLUDE_DIR} 24 | ${STB_INCLUDE_DIR} 25 | ) 26 | 27 | ADD_EXECUTABLE(Vorogen ${SOURCES} ${HEADERS}) 28 | 29 | TARGET_LINK_LIBRARIES(Vorogen 30 | ## 3rdparty 31 | ${GLFW_LIBRARIES} 32 | ${TINYCTHREAD_LIBRARIES} 33 | 34 | ## System libraries 35 | ${OPENGL_LIBRARIES} 36 | ${PLATFORM_LIBRARIES} 37 | ${OS_SPECIFIC_LIBRARIES} 38 | ) 39 | 40 | ## Install 41 | INSTALL(TARGETS Vorogen DESTINATION ${MTCL_INSTALL_DIR}) 42 | INSTALL(DIRECTORY ../dataset DESTINATION ${MTCL_INSTALL_DIR}) 43 | 44 | IF(APPLE) 45 | SET_TARGET_PROPERTIES( 46 | Vorogen 47 | PROPERTIES 48 | BUILD_WITH_INSTALL_RPATH 1 49 | INSTALL_RPATH "@loader_path/" 50 | ) 51 | ENDIF(APPLE) 52 | 53 | IF(UNIX AND NOT APPLE) 54 | SET_TARGET_PROPERTIES( 55 | Vorogen 56 | PROPERTIES 57 | BUILD_WITH_INSTALL_RPATH 1 58 | INSTALL_RPATH "$ORIGIN/" 59 | ) 60 | ENDIF(UNIX AND NOT APPLE) 61 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ## Find source and headers 2 | 3 | FILE(GLOB SOURCES 4 | src/clipboard.c 5 | src/context.c 6 | src/gamma.c 7 | src/init.c 8 | src/input.c 9 | src/joystick.c 10 | src/monitor.c 11 | src/time.c 12 | src/window.c 13 | ) 14 | 15 | IF(WIN32) 16 | FILE(GLOB OS_HEADERS src/win32_*.h src/wgl_*.h) 17 | FILE(GLOB OS_SOURCES src/win32_*.c src/wgl_*.c) 18 | ADD_DEFINITIONS(-D_GLFW_WIN32) 19 | ADD_DEFINITIONS(-D_GLFW_WGL) 20 | ENDIF(WIN32) 21 | 22 | IF(APPLE) 23 | FILE(GLOB OS_HEADERS src/cocoa_*.h src/nsgl_*.h) 24 | FILE(GLOB OS_SOURCES src/cocoa_*.c src/nsgl_*.c src/cocoa_*.m src/nsgl_*.m) 25 | ADD_DEFINITIONS(-D_GLFW_COCOA) 26 | ADD_DEFINITIONS(-D_GLFW_NSGL) 27 | ENDIF(APPLE) 28 | 29 | IF(UNIX AND NOT APPLE) 30 | FILE(GLOB OS_HEADERS src/x11_*.h src/glx_*.h) 31 | FILE(GLOB OS_SOURCES src/x11_*.c src/glx_*.c) 32 | ADD_DEFINITIONS(-D_GLFW_X11) 33 | ADD_DEFINITIONS(-D_GLFW_GLX) 34 | ADD_DEFINITIONS(-D_GLFW_HAS_GLXGETPROCADDRESS) 35 | ENDIF(UNIX AND NOT APPLE) 36 | 37 | IF(CMAKE_HAS_SORT) 38 | LIST(SORT SOURCES) 39 | LIST(SORT OS_HEADERS) 40 | LIST(SORT OS_SOURCES) 41 | ENDIF(CMAKE_HAS_SORT) 42 | 43 | ## Build 44 | ADD_DEFINITIONS(-D_GLFW_USE_OPENGL) 45 | ADD_DEFINITIONS(-D_GLFW_USE_MENUBAR) 46 | ADD_DEFINITIONS(-D_GLFW_USE_CHDIR) 47 | 48 | INCLUDE_DIRECTORIES( 49 | include 50 | ) 51 | 52 | ADD_LIBRARY(glfw ${SOURCES} ${OS_HEADERS} ${OS_SOURCES}) 53 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/src/time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW - An OpenGL library 3 | // Platform: Any 4 | // API version: 3.0 5 | // WWW: http://www.glfw.org/ 6 | //------------------------------------------------------------------------ 7 | // Copyright (c) 2002-2006 Marcus Geelnard 8 | // Copyright (c) 2006-2010 Camilla Berglund 9 | // 10 | // This software is provided 'as-is', without any express or implied 11 | // warranty. In no event will the authors be held liable for any damages 12 | // arising from the use of this software. 13 | // 14 | // Permission is granted to anyone to use this software for any purpose, 15 | // including commercial applications, and to alter it and redistribute it 16 | // freely, subject to the following restrictions: 17 | // 18 | // 1. The origin of this software must not be misrepresented; you must not 19 | // claim that you wrote the original software. If you use this software 20 | // in a product, an acknowledgment in the product documentation would 21 | // be appreciated but is not required. 22 | // 23 | // 2. Altered source versions must be plainly marked as such, and must not 24 | // be misrepresented as being the original software. 25 | // 26 | // 3. This notice may not be removed or altered from any source 27 | // distribution. 28 | // 29 | //======================================================================== 30 | 31 | #include "internal.h" 32 | 33 | 34 | ////////////////////////////////////////////////////////////////////////// 35 | ////// GLFW public API ////// 36 | ////////////////////////////////////////////////////////////////////////// 37 | 38 | GLFWAPI double glfwGetTime(void) 39 | { 40 | _GLFW_REQUIRE_INIT_OR_RETURN(0.0); 41 | return _glfwPlatformGetTime(); 42 | } 43 | 44 | GLFWAPI void glfwSetTime(double time) 45 | { 46 | _GLFW_REQUIRE_INIT(); 47 | _glfwPlatformSetTime(time); 48 | } 49 | 50 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/src/config.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW - An OpenGL library 3 | // Platform: Any 4 | // API version: 3.0 5 | // WWW: http://www.glfw.org/ 6 | //------------------------------------------------------------------------ 7 | // Copyright (c) 2010 Camilla Berglund 8 | // 9 | // This software is provided 'as-is', without any express or implied 10 | // warranty. In no event will the authors be held liable for any damages 11 | // arising from the use of this software. 12 | // 13 | // Permission is granted to anyone to use this software for any purpose, 14 | // including commercial applications, and to alter it and redistribute it 15 | // freely, subject to the following restrictions: 16 | // 17 | // 1. The origin of this software must not be misrepresented; you must not 18 | // claim that you wrote the original software. If you use this software 19 | // in a product, an acknowledgment in the product documentation would 20 | // be appreciated but is not required. 21 | // 22 | // 2. Altered source versions must be plainly marked as such, and must not 23 | // be misrepresented as being the original software. 24 | // 25 | // 3. This notice may not be removed or altered from any source 26 | // distribution. 27 | // 28 | //======================================================================== 29 | // As config.h.in, this file is used by CMake to produce the config.h shared 30 | // configuration header file. If you are adding a feature requiring 31 | // conditional compilation, this is the proper place to add the macros. 32 | //======================================================================== 33 | // As config.h, this file defines compile-time build options and macros for 34 | // all platforms supported by GLFW. As this is a generated file, don't modify 35 | // it. Instead, you should modify the config.h.in file. 36 | //======================================================================== 37 | 38 | // The GLFW version as used by glfwGetVersionString 39 | #define _GLFW_VERSION_FULL "3.0.1" 40 | 41 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/src/clipboard.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW - An OpenGL library 3 | // Platform: Any 4 | // API version: 3.0 5 | // WWW: http://www.glfw.org/ 6 | //------------------------------------------------------------------------ 7 | // Copyright (c) 2010 Camilla Berglund 8 | // 9 | // This software is provided 'as-is', without any express or implied 10 | // warranty. In no event will the authors be held liable for any damages 11 | // arising from the use of this software. 12 | // 13 | // Permission is granted to anyone to use this software for any purpose, 14 | // including commercial applications, and to alter it and redistribute it 15 | // freely, subject to the following restrictions: 16 | // 17 | // 1. The origin of this software must not be misrepresented; you must not 18 | // claim that you wrote the original software. If you use this software 19 | // in a product, an acknowledgment in the product documentation would 20 | // be appreciated but is not required. 21 | // 22 | // 2. Altered source versions must be plainly marked as such, and must not 23 | // be misrepresented as being the original software. 24 | // 25 | // 3. This notice may not be removed or altered from any source 26 | // distribution. 27 | // 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #include 33 | #include 34 | 35 | 36 | ////////////////////////////////////////////////////////////////////////// 37 | ////// GLFW public API ////// 38 | ////////////////////////////////////////////////////////////////////////// 39 | 40 | GLFWAPI void glfwSetClipboardString(GLFWwindow* handle, const char* string) 41 | { 42 | _GLFWwindow* window = (_GLFWwindow*) handle; 43 | _GLFW_REQUIRE_INIT(); 44 | _glfwPlatformSetClipboardString(window, string); 45 | } 46 | 47 | GLFWAPI const char* glfwGetClipboardString(GLFWwindow* handle) 48 | { 49 | _GLFWwindow* window = (_GLFWwindow*) handle; 50 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 51 | return _glfwPlatformGetClipboardString(window); 52 | } 53 | 54 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/deps/getopt.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * getopt.h - competent and free getopt library. 3 | * $Header: /cvsroot/freegetopt/freegetopt/getopt.h,v 1.2 2003/10/26 03:10:20 vindaci Exp $ 4 | * 5 | * Copyright (c)2002-2003 Mark K. Kim 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in 17 | * the documentation and/or other materials provided with the 18 | * distribution. 19 | * 20 | * * Neither the original author of this software nor the names of its 21 | * contributors may be used to endorse or promote products derived 22 | * from this software without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 31 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 32 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 33 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 34 | * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 35 | * DAMAGE. 36 | */ 37 | #ifndef GETOPT_H_ 38 | #define GETOPT_H_ 39 | 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif 44 | 45 | 46 | extern char* optarg; 47 | extern int optind; 48 | extern int opterr; 49 | extern int optopt; 50 | 51 | int getopt(int argc, char** argv, const char* optstr); 52 | 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | 59 | #endif /* GETOPT_H_ */ 60 | 61 | 62 | /* vim:ts=3 63 | */ 64 | -------------------------------------------------------------------------------- /tests/3rdparty/tinycthread/README.txt: -------------------------------------------------------------------------------- 1 | TinyCThread v1.1 2 | ================ 3 | 4 | http://tinycthread.bitsnbites.eu 5 | 6 | 7 | About 8 | ----- 9 | 10 | TinyCThread is a minimalist, portable, threading library for C, intended to 11 | make it easy to create multi threaded C applications. 12 | 13 | The library is closesly modeled after the C11 standard, but only a subset is 14 | implemented at the moment. 15 | 16 | See the documentation in the doc/html directory for more information. 17 | 18 | 19 | Using TinyCThread 20 | ----------------- 21 | 22 | To use TinyCThread in your own project, just add tinycthread.c and 23 | tinycthread.h to your project. In your own code, do: 24 | 25 | #include 26 | 27 | 28 | Building the test programs 29 | -------------------------- 30 | 31 | From the test folder, issue one of the following commands: 32 | 33 | Linux, Mac OS X, OpenSolaris etc: 34 | make (you may need to use gmake on some systems) 35 | 36 | Windows/MinGW: 37 | mingw32-make 38 | 39 | Windows/MS Visual Studio: 40 | nmake /f Makefile.msvc 41 | 42 | 43 | History 44 | ------- 45 | 46 | v1.1 - 2012.9.8 47 | - First release. 48 | - Updated API to better match the final specification (e.g. removed xtime). 49 | - Some functionality still missing (mtx_timedlock, TSS destructors under 50 | Windows, ...). 51 | 52 | v1.0 - Never released 53 | - Development version based on C11 specification draft. 54 | 55 | 56 | 57 | License 58 | ------- 59 | 60 | Copyright (c) 2012 Marcus Geelnard 61 | 62 | This software is provided 'as-is', without any express or implied 63 | warranty. In no event will the authors be held liable for any damages 64 | arising from the use of this software. 65 | 66 | Permission is granted to anyone to use this software for any purpose, 67 | including commercial applications, and to alter it and redistribute it 68 | freely, subject to the following restrictions: 69 | 70 | 1. The origin of this software must not be misrepresented; you must not 71 | claim that you wrote the original software. If you use this software 72 | in a product, an acknowledgment in the product documentation would be 73 | appreciated but is not required. 74 | 75 | 2. Altered source versions must be plainly marked as such, and must not be 76 | misrepresented as being the original software. 77 | 78 | 3. This notice may not be removed or altered from any source 79 | distribution. 80 | 81 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/src/cocoa_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW - An OpenGL library 3 | // Platform: Cocoa 4 | // API Version: 3.0 5 | // WWW: http://www.glfw.org/ 6 | //------------------------------------------------------------------------ 7 | // Copyright (c) 2009-2010 Camilla Berglund 8 | // 9 | // This software is provided 'as-is', without any express or implied 10 | // warranty. In no event will the authors be held liable for any damages 11 | // arising from the use of this software. 12 | // 13 | // Permission is granted to anyone to use this software for any purpose, 14 | // including commercial applications, and to alter it and redistribute it 15 | // freely, subject to the following restrictions: 16 | // 17 | // 1. The origin of this software must not be misrepresented; you must not 18 | // claim that you wrote the original software. If you use this software 19 | // in a product, an acknowledgment in the product documentation would 20 | // be appreciated but is not required. 21 | // 22 | // 2. Altered source versions must be plainly marked as such, and must not 23 | // be misrepresented as being the original software. 24 | // 25 | // 3. This notice may not be removed or altered from any source 26 | // distribution. 27 | // 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #include 33 | 34 | 35 | // Return raw time 36 | // 37 | static uint64_t getRawTime(void) 38 | { 39 | return mach_absolute_time(); 40 | } 41 | 42 | 43 | ////////////////////////////////////////////////////////////////////////// 44 | ////// GLFW internal API ////// 45 | ////////////////////////////////////////////////////////////////////////// 46 | 47 | // Initialise timer 48 | // 49 | void _glfwInitTimer(void) 50 | { 51 | mach_timebase_info_data_t info; 52 | mach_timebase_info(&info); 53 | 54 | _glfw.ns.timer.resolution = (double) info.numer / (info.denom * 1.0e9); 55 | _glfw.ns.timer.base = getRawTime(); 56 | } 57 | 58 | 59 | ////////////////////////////////////////////////////////////////////////// 60 | ////// GLFW platform API ////// 61 | ////////////////////////////////////////////////////////////////////////// 62 | 63 | double _glfwPlatformGetTime(void) 64 | { 65 | return (double) (getRawTime() - _glfw.ns.timer.base) * 66 | _glfw.ns.timer.resolution; 67 | } 68 | 69 | void _glfwPlatformSetTime(double time) 70 | { 71 | _glfw.ns.timer.base = getRawTime() - 72 | (uint64_t) (time / _glfw.ns.timer.resolution); 73 | } 74 | 75 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/src/nsgl_platform.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW - An OpenGL library 3 | // Platform: NSOpenGL 4 | // API Version: 3.0 5 | // WWW: http://www.glfw.org/ 6 | //------------------------------------------------------------------------ 7 | // Copyright (c) 2009-2010 Camilla Berglund 8 | // 9 | // This software is provided 'as-is', without any express or implied 10 | // warranty. In no event will the authors be held liable for any damages 11 | // arising from the use of this software. 12 | // 13 | // Permission is granted to anyone to use this software for any purpose, 14 | // including commercial applications, and to alter it and redistribute it 15 | // freely, subject to the following restrictions: 16 | // 17 | // 1. The origin of this software must not be misrepresented; you must not 18 | // claim that you wrote the original software. If you use this software 19 | // in a product, an acknowledgment in the product documentation would 20 | // be appreciated but is not required. 21 | // 22 | // 2. Altered source versions must be plainly marked as such, and must not 23 | // be misrepresented as being the original software. 24 | // 25 | // 3. This notice may not be removed or altered from any source 26 | // distribution. 27 | // 28 | //======================================================================== 29 | 30 | #ifndef _nsgl_platform_h_ 31 | #define _nsgl_platform_h_ 32 | 33 | 34 | #define _GLFW_PLATFORM_FBCONFIG 35 | #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextNSGL nsgl 36 | #define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryNSGL nsgl 37 | 38 | 39 | //======================================================================== 40 | // GLFW platform specific types 41 | //======================================================================== 42 | 43 | //------------------------------------------------------------------------ 44 | // Platform-specific OpenGL context structure 45 | //------------------------------------------------------------------------ 46 | typedef struct _GLFWcontextNSGL 47 | { 48 | id pixelFormat; 49 | id context; 50 | } _GLFWcontextNSGL; 51 | 52 | 53 | //------------------------------------------------------------------------ 54 | // Platform-specific library global data for NSGL 55 | //------------------------------------------------------------------------ 56 | typedef struct _GLFWlibraryNSGL 57 | { 58 | // dlopen handle for dynamically loading OpenGL extension entry points 59 | void* framework; 60 | 61 | // TLS key for per-thread current context/window 62 | pthread_key_t current; 63 | 64 | } _GLFWlibraryNSGL; 65 | 66 | 67 | #endif // _nsgl_platform_h_ 68 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/src/cocoa_clipboard.m: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW - An OpenGL library 3 | // Platform: Cocoa 4 | // API version: 3.0 5 | // WWW: http://www.glfw.org/ 6 | //------------------------------------------------------------------------ 7 | // Copyright (c) 2010 Camilla Berglund 8 | // 9 | // This software is provided 'as-is', without any express or implied 10 | // warranty. In no event will the authors be held liable for any damages 11 | // arising from the use of this software. 12 | // 13 | // Permission is granted to anyone to use this software for any purpose, 14 | // including commercial applications, and to alter it and redistribute it 15 | // freely, subject to the following restrictions: 16 | // 17 | // 1. The origin of this software must not be misrepresented; you must not 18 | // claim that you wrote the original software. If you use this software 19 | // in a product, an acknowledgment in the product documentation would 20 | // be appreciated but is not required. 21 | // 22 | // 2. Altered source versions must be plainly marked as such, and must not 23 | // be misrepresented as being the original software. 24 | // 25 | // 3. This notice may not be removed or altered from any source 26 | // distribution. 27 | // 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #include 33 | #include 34 | 35 | 36 | ////////////////////////////////////////////////////////////////////////// 37 | ////// GLFW platform API ////// 38 | ////////////////////////////////////////////////////////////////////////// 39 | 40 | void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) 41 | { 42 | NSArray* types = [NSArray arrayWithObjects:NSStringPboardType, nil]; 43 | 44 | NSPasteboard* pasteboard = [NSPasteboard generalPasteboard]; 45 | [pasteboard declareTypes:types owner:nil]; 46 | [pasteboard setString:[NSString stringWithUTF8String:string] 47 | forType:NSStringPboardType]; 48 | } 49 | 50 | const char* _glfwPlatformGetClipboardString(_GLFWwindow* window) 51 | { 52 | NSPasteboard* pasteboard = [NSPasteboard generalPasteboard]; 53 | 54 | if (![[pasteboard types] containsObject:NSStringPboardType]) 55 | { 56 | _glfwInputError(GLFW_FORMAT_UNAVAILABLE, NULL); 57 | return NULL; 58 | } 59 | 60 | NSString* object = [pasteboard stringForType:NSStringPboardType]; 61 | if (!object) 62 | { 63 | _glfwInputError(GLFW_PLATFORM_ERROR, 64 | "Cocoa: Failed to retrieve object from pasteboard"); 65 | return NULL; 66 | } 67 | 68 | free(_glfw.ns.clipboardString); 69 | _glfw.ns.clipboardString = strdup([object UTF8String]); 70 | 71 | return _glfw.ns.clipboardString; 72 | } 73 | 74 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/src/joystick.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW - An OpenGL library 3 | // Platform: Any 4 | // API version: 3.0 5 | // WWW: http://www.glfw.org/ 6 | //------------------------------------------------------------------------ 7 | // Copyright (c) 2002-2006 Marcus Geelnard 8 | // Copyright (c) 2006-2010 Camilla Berglund 9 | // 10 | // This software is provided 'as-is', without any express or implied 11 | // warranty. In no event will the authors be held liable for any damages 12 | // arising from the use of this software. 13 | // 14 | // Permission is granted to anyone to use this software for any purpose, 15 | // including commercial applications, and to alter it and redistribute it 16 | // freely, subject to the following restrictions: 17 | // 18 | // 1. The origin of this software must not be misrepresented; you must not 19 | // claim that you wrote the original software. If you use this software 20 | // in a product, an acknowledgment in the product documentation would 21 | // be appreciated but is not required. 22 | // 23 | // 2. Altered source versions must be plainly marked as such, and must not 24 | // be misrepresented as being the original software. 25 | // 26 | // 3. This notice may not be removed or altered from any source 27 | // distribution. 28 | // 29 | //======================================================================== 30 | 31 | #include "internal.h" 32 | 33 | 34 | ////////////////////////////////////////////////////////////////////////// 35 | ////// GLFW public API ////// 36 | ////////////////////////////////////////////////////////////////////////// 37 | 38 | GLFWAPI int glfwJoystickPresent(int joy) 39 | { 40 | _GLFW_REQUIRE_INIT_OR_RETURN(0); 41 | 42 | if (joy < 0 || joy > GLFW_JOYSTICK_LAST) 43 | { 44 | _glfwInputError(GLFW_INVALID_ENUM, NULL); 45 | return 0; 46 | } 47 | 48 | return _glfwPlatformJoystickPresent(joy); 49 | } 50 | 51 | GLFWAPI const float* glfwGetJoystickAxes(int joy, int* count) 52 | { 53 | *count = 0; 54 | 55 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 56 | 57 | if (joy < 0 || joy > GLFW_JOYSTICK_LAST) 58 | { 59 | _glfwInputError(GLFW_INVALID_ENUM, NULL); 60 | return NULL; 61 | } 62 | 63 | return _glfwPlatformGetJoystickAxes(joy, count); 64 | } 65 | 66 | GLFWAPI const unsigned char* glfwGetJoystickButtons(int joy, int* count) 67 | { 68 | *count = 0; 69 | 70 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 71 | 72 | if (joy < 0 || joy > GLFW_JOYSTICK_LAST) 73 | { 74 | _glfwInputError(GLFW_INVALID_ENUM, NULL); 75 | return NULL; 76 | } 77 | 78 | return _glfwPlatformGetJoystickButtons(joy, count); 79 | } 80 | 81 | GLFWAPI const char* glfwGetJoystickName(int joy) 82 | { 83 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 84 | 85 | if (joy < 0 || joy > GLFW_JOYSTICK_LAST) 86 | { 87 | _glfwInputError(GLFW_INVALID_ENUM, NULL); 88 | return NULL; 89 | } 90 | 91 | return _glfwPlatformGetJoystickName(joy); 92 | } 93 | 94 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/src/egl_platform.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW - An OpenGL library 3 | // Platform: EGL 4 | // API version: 3.0 5 | // WWW: http://www.glfw.org/ 6 | //------------------------------------------------------------------------ 7 | // Copyright (c) 2002-2006 Marcus Geelnard 8 | // Copyright (c) 2006-2010 Camilla Berglund 9 | // 10 | // This software is provided 'as-is', without any express or implied 11 | // warranty. In no event will the authors be held liable for any damages 12 | // arising from the use of this software. 13 | // 14 | // Permission is granted to anyone to use this software for any purpose, 15 | // including commercial applications, and to alter it and redistribute it 16 | // freely, subject to the following restrictions: 17 | // 18 | // 1. The origin of this software must not be misrepresented; you must not 19 | // claim that you wrote the original software. If you use this software 20 | // in a product, an acknowledgment in the product documentation would 21 | // be appreciated but is not required. 22 | // 23 | // 2. Altered source versions must be plainly marked as such, and must not 24 | // be misrepresented as being the original software. 25 | // 26 | // 3. This notice may not be removed or altered from any source 27 | // distribution. 28 | // 29 | //======================================================================== 30 | 31 | #ifndef _egl_platform_h_ 32 | #define _egl_platform_h_ 33 | 34 | #include 35 | 36 | // This path may need to be changed if you build GLFW using your own setup 37 | // We ship and use our own copy of eglext.h since GLFW uses fairly new 38 | // extensions and not all operating systems come with an up-to-date version 39 | #include "../deps/EGL/eglext.h" 40 | 41 | // Do we have support for dlopen/dlsym? 42 | #if defined(_GLFW_HAS_DLOPEN) 43 | #include 44 | #endif 45 | 46 | #define _GLFW_PLATFORM_FBCONFIG EGLConfig egl 47 | #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextEGL egl 48 | #define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryEGL egl 49 | 50 | 51 | //======================================================================== 52 | // GLFW platform specific types 53 | //======================================================================== 54 | 55 | //------------------------------------------------------------------------ 56 | // Platform-specific OpenGL context structure 57 | //------------------------------------------------------------------------ 58 | typedef struct _GLFWcontextEGL 59 | { 60 | EGLConfig config; 61 | EGLContext context; 62 | EGLSurface surface; 63 | 64 | #if defined(_GLFW_X11) 65 | XVisualInfo* visual; 66 | #endif 67 | } _GLFWcontextEGL; 68 | 69 | 70 | //------------------------------------------------------------------------ 71 | // Platform-specific library global data for EGL 72 | //------------------------------------------------------------------------ 73 | typedef struct _GLFWlibraryEGL 74 | { 75 | EGLDisplay display; 76 | EGLint versionMajor, versionMinor; 77 | 78 | GLboolean KHR_create_context; 79 | 80 | } _GLFWlibraryEGL; 81 | 82 | 83 | #endif // _egl_platform_h_ 84 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/src/win32_gamma.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW - An OpenGL library 3 | // Platform: Win32 4 | // API version: 3.0 5 | // WWW: http://www.glfw.org/ 6 | //------------------------------------------------------------------------ 7 | // Copyright (c) 2010 Camilla Berglund 8 | // 9 | // This software is provided 'as-is', without any express or implied 10 | // warranty. In no event will the authors be held liable for any damages 11 | // arising from the use of this software. 12 | // 13 | // Permission is granted to anyone to use this software for any purpose, 14 | // including commercial applications, and to alter it and redistribute it 15 | // freely, subject to the following restrictions: 16 | // 17 | // 1. The origin of this software must not be misrepresented; you must not 18 | // claim that you wrote the original software. If you use this software 19 | // in a product, an acknowledgment in the product documentation would 20 | // be appreciated but is not required. 21 | // 22 | // 2. Altered source versions must be plainly marked as such, and must not 23 | // be misrepresented as being the original software. 24 | // 25 | // 3. This notice may not be removed or altered from any source 26 | // distribution. 27 | // 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #include 33 | 34 | 35 | ////////////////////////////////////////////////////////////////////////// 36 | ////// GLFW platform API ////// 37 | ////////////////////////////////////////////////////////////////////////// 38 | 39 | void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp) 40 | { 41 | HDC dc; 42 | WORD values[768]; 43 | DISPLAY_DEVICE display; 44 | 45 | ZeroMemory(&display, sizeof(DISPLAY_DEVICE)); 46 | display.cb = sizeof(DISPLAY_DEVICE); 47 | EnumDisplayDevices(monitor->win32.name, 0, &display, 0); 48 | 49 | dc = CreateDC(L"DISPLAY", display.DeviceString, NULL, NULL); 50 | GetDeviceGammaRamp(dc, values); 51 | DeleteDC(dc); 52 | 53 | _glfwAllocGammaRamp(ramp, 256); 54 | 55 | memcpy(ramp->red, values + 0, 256 * sizeof(unsigned short)); 56 | memcpy(ramp->green, values + 256, 256 * sizeof(unsigned short)); 57 | memcpy(ramp->blue, values + 512, 256 * sizeof(unsigned short)); 58 | } 59 | 60 | void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp) 61 | { 62 | HDC dc; 63 | WORD values[768]; 64 | DISPLAY_DEVICE display; 65 | 66 | if (ramp->size != 256) 67 | { 68 | _glfwInputError(GLFW_PLATFORM_ERROR, 69 | "Win32: Gamma ramp size must be 256"); 70 | return; 71 | } 72 | 73 | memcpy(values + 0, ramp->red, 256 * sizeof(unsigned short)); 74 | memcpy(values + 256, ramp->green, 256 * sizeof(unsigned short)); 75 | memcpy(values + 512, ramp->blue, 256 * sizeof(unsigned short)); 76 | 77 | ZeroMemory(&display, sizeof(DISPLAY_DEVICE)); 78 | display.cb = sizeof(DISPLAY_DEVICE); 79 | EnumDisplayDevices(monitor->win32.name, 0, &display, 0); 80 | 81 | dc = CreateDC(L"DISPLAY", display.DeviceString, NULL, NULL); 82 | SetDeviceGammaRamp(dc, values); 83 | DeleteDC(dc); 84 | } 85 | 86 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/src/win32_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW - An OpenGL library 3 | // Platform: Win32 4 | // API version: 3.0 5 | // WWW: http://www.glfw.org/ 6 | //------------------------------------------------------------------------ 7 | // Copyright (c) 2002-2006 Marcus Geelnard 8 | // Copyright (c) 2006-2010 Camilla Berglund 9 | // 10 | // This software is provided 'as-is', without any express or implied 11 | // warranty. In no event will the authors be held liable for any damages 12 | // arising from the use of this software. 13 | // 14 | // Permission is granted to anyone to use this software for any purpose, 15 | // including commercial applications, and to alter it and redistribute it 16 | // freely, subject to the following restrictions: 17 | // 18 | // 1. The origin of this software must not be misrepresented; you must not 19 | // claim that you wrote the original software. If you use this software 20 | // in a product, an acknowledgment in the product documentation would 21 | // be appreciated but is not required. 22 | // 23 | // 2. Altered source versions must be plainly marked as such, and must not 24 | // be misrepresented as being the original software. 25 | // 26 | // 3. This notice may not be removed or altered from any source 27 | // distribution. 28 | // 29 | //======================================================================== 30 | 31 | #include "internal.h" 32 | 33 | 34 | ////////////////////////////////////////////////////////////////////////// 35 | ////// GLFW internal API ////// 36 | ////////////////////////////////////////////////////////////////////////// 37 | 38 | // Initialise timer 39 | // 40 | void _glfwInitTimer(void) 41 | { 42 | __int64 freq; 43 | 44 | if (QueryPerformanceFrequency((LARGE_INTEGER*) &freq)) 45 | { 46 | _glfw.win32.timer.hasPC = GL_TRUE; 47 | _glfw.win32.timer.resolution = 1.0 / (double) freq; 48 | QueryPerformanceCounter((LARGE_INTEGER*) &_glfw.win32.timer.t0_64); 49 | } 50 | else 51 | { 52 | _glfw.win32.timer.hasPC = GL_FALSE; 53 | _glfw.win32.timer.resolution = 0.001; // winmm resolution is 1 ms 54 | _glfw.win32.timer.t0_32 = _glfw_timeGetTime(); 55 | } 56 | } 57 | 58 | 59 | ////////////////////////////////////////////////////////////////////////// 60 | ////// GLFW platform API ////// 61 | ////////////////////////////////////////////////////////////////////////// 62 | 63 | double _glfwPlatformGetTime(void) 64 | { 65 | double t; 66 | __int64 t_64; 67 | 68 | if (_glfw.win32.timer.hasPC) 69 | { 70 | QueryPerformanceCounter((LARGE_INTEGER*) &t_64); 71 | t = (double)(t_64 - _glfw.win32.timer.t0_64); 72 | } 73 | else 74 | t = (double)(_glfw_timeGetTime() - _glfw.win32.timer.t0_32); 75 | 76 | return t * _glfw.win32.timer.resolution; 77 | } 78 | 79 | void _glfwPlatformSetTime(double t) 80 | { 81 | __int64 t_64; 82 | 83 | if (_glfw.win32.timer.hasPC) 84 | { 85 | QueryPerformanceCounter((LARGE_INTEGER*) &t_64); 86 | _glfw.win32.timer.t0_64 = t_64 - (__int64) (t / _glfw.win32.timer.resolution); 87 | } 88 | else 89 | _glfw.win32.timer.t0_32 = _glfw_timeGetTime() - (int)(t * 1000.0); 90 | } 91 | 92 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/src/x11_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW - An OpenGL library 3 | // Platform: X11 4 | // API version: 3.0 5 | // WWW: http://www.glfw.org/ 6 | //------------------------------------------------------------------------ 7 | // Copyright (c) 2002-2006 Marcus Geelnard 8 | // Copyright (c) 2006-2010 Camilla Berglund 9 | // 10 | // This software is provided 'as-is', without any express or implied 11 | // warranty. In no event will the authors be held liable for any damages 12 | // arising from the use of this software. 13 | // 14 | // Permission is granted to anyone to use this software for any purpose, 15 | // including commercial applications, and to alter it and redistribute it 16 | // freely, subject to the following restrictions: 17 | // 18 | // 1. The origin of this software must not be misrepresented; you must not 19 | // claim that you wrote the original software. If you use this software 20 | // in a product, an acknowledgment in the product documentation would 21 | // be appreciated but is not required. 22 | // 23 | // 2. Altered source versions must be plainly marked as such, and must not 24 | // be misrepresented as being the original software. 25 | // 26 | // 3. This notice may not be removed or altered from any source 27 | // distribution. 28 | // 29 | //======================================================================== 30 | 31 | #include "internal.h" 32 | 33 | #include 34 | #include 35 | 36 | 37 | // Return raw time 38 | // 39 | static uint64_t getRawTime(void) 40 | { 41 | #if defined(CLOCK_MONOTONIC) 42 | if (_glfw.x11.timer.monotonic) 43 | { 44 | struct timespec ts; 45 | 46 | clock_gettime(CLOCK_MONOTONIC, &ts); 47 | return (uint64_t) ts.tv_sec * (uint64_t) 1000000000 + (uint64_t) ts.tv_nsec; 48 | } 49 | else 50 | #endif 51 | { 52 | struct timeval tv; 53 | 54 | gettimeofday(&tv, NULL); 55 | return (uint64_t) tv.tv_sec * (uint64_t) 1000000 + (uint64_t) tv.tv_usec; 56 | } 57 | } 58 | 59 | 60 | ////////////////////////////////////////////////////////////////////////// 61 | ////// GLFW internal API ////// 62 | ////////////////////////////////////////////////////////////////////////// 63 | 64 | // Initialise timer 65 | // 66 | void _glfwInitTimer(void) 67 | { 68 | #if defined(CLOCK_MONOTONIC) 69 | struct timespec ts; 70 | 71 | if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) 72 | { 73 | _glfw.x11.timer.monotonic = GL_TRUE; 74 | _glfw.x11.timer.resolution = 1e-9; 75 | } 76 | else 77 | #endif 78 | { 79 | _glfw.x11.timer.resolution = 1e-6; 80 | } 81 | 82 | _glfw.x11.timer.base = getRawTime(); 83 | } 84 | 85 | 86 | ////////////////////////////////////////////////////////////////////////// 87 | ////// GLFW platform API ////// 88 | ////////////////////////////////////////////////////////////////////////// 89 | 90 | double _glfwPlatformGetTime(void) 91 | { 92 | return (double) (getRawTime() - _glfw.x11.timer.base) * 93 | _glfw.x11.timer.resolution; 94 | } 95 | 96 | void _glfwPlatformSetTime(double time) 97 | { 98 | _glfw.x11.timer.base = getRawTime() - 99 | (uint64_t) (time / _glfw.x11.timer.resolution); 100 | } 101 | 102 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/src/cocoa_gamma.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW - An OpenGL library 3 | // Platform: Cocoa 4 | // API version: 3.0 5 | // WWW: http://www.glfw.org/ 6 | //------------------------------------------------------------------------ 7 | // Copyright (c) 2010 Camilla Berglund 8 | // 9 | // This software is provided 'as-is', without any express or implied 10 | // warranty. In no event will the authors be held liable for any damages 11 | // arising from the use of this software. 12 | // 13 | // Permission is granted to anyone to use this software for any purpose, 14 | // including commercial applications, and to alter it and redistribute it 15 | // freely, subject to the following restrictions: 16 | // 17 | // 1. The origin of this software must not be misrepresented; you must not 18 | // claim that you wrote the original software. If you use this software 19 | // in a product, an acknowledgment in the product documentation would 20 | // be appreciated but is not required. 21 | // 22 | // 2. Altered source versions must be plainly marked as such, and must not 23 | // be misrepresented as being the original software. 24 | // 25 | // 3. This notice may not be removed or altered from any source 26 | // distribution. 27 | // 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | 38 | 39 | ////////////////////////////////////////////////////////////////////////// 40 | ////// GLFW platform API ////// 41 | ////////////////////////////////////////////////////////////////////////// 42 | 43 | void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp) 44 | { 45 | uint32_t i, size = CGDisplayGammaTableCapacity(monitor->ns.displayID); 46 | CGGammaValue* values = (CGGammaValue*) malloc(size * 3 * sizeof(CGGammaValue)); 47 | 48 | CGGetDisplayTransferByTable(monitor->ns.displayID, 49 | size, 50 | values, 51 | values + size, 52 | values + size * 2, 53 | &size); 54 | 55 | _glfwAllocGammaRamp(ramp, size); 56 | 57 | for (i = 0; i < size; i++) 58 | { 59 | ramp->red[i] = (unsigned short) (values[i] * 65535); 60 | ramp->green[i] = (unsigned short) (values[i + size] * 65535); 61 | ramp->blue[i] = (unsigned short) (values[i + size * 2] * 65535); 62 | } 63 | 64 | free(values); 65 | } 66 | 67 | void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp) 68 | { 69 | int i; 70 | CGGammaValue* values = (CGGammaValue*) malloc(ramp->size * 3 * sizeof(CGGammaValue)); 71 | 72 | for (i = 0; i < ramp->size; i++) 73 | { 74 | values[i] = ramp->red[i] / 65535.f; 75 | values[i + ramp->size] = ramp->green[i] / 65535.f; 76 | values[i + ramp->size * 2] = ramp->blue[i] / 65535.f; 77 | } 78 | 79 | CGSetDisplayTransferByTable(monitor->ns.displayID, 80 | ramp->size, 81 | values, 82 | values + ramp->size, 83 | values + ramp->size * 2); 84 | 85 | free(values); 86 | } 87 | 88 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | include_directories(${GLFW_SOURCE_DIR}/src 3 | ${GLFW_BINARY_DIR}/src 4 | ${glfw_INCLUDE_DIRS}) 5 | 6 | if (MSVC) 7 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) 8 | endif() 9 | 10 | set(common_HEADERS ${GLFW_SOURCE_DIR}/include/GLFW/glfw3.h internal.h) 11 | set(common_SOURCES clipboard.c context.c gamma.c init.c input.c joystick.c 12 | monitor.c time.c window.c) 13 | 14 | if (_GLFW_COCOA) 15 | set(glfw_HEADERS ${common_HEADERS} cocoa_platform.h) 16 | set(glfw_SOURCES ${common_SOURCES} cocoa_clipboard.m cocoa_gamma.c 17 | cocoa_init.m cocoa_joystick.m cocoa_monitor.m cocoa_time.c 18 | cocoa_window.m) 19 | elseif (_GLFW_WIN32) 20 | set(glfw_HEADERS ${common_HEADERS} win32_platform.h) 21 | set(glfw_SOURCES ${common_SOURCES} win32_clipboard.c win32_gamma.c 22 | win32_init.c win32_joystick.c win32_monitor.c win32_time.c 23 | win32_window.c) 24 | elseif (_GLFW_X11) 25 | set(glfw_HEADERS ${common_HEADERS} x11_platform.h) 26 | set(glfw_SOURCES ${common_SOURCES} x11_clipboard.c x11_gamma.c x11_init.c 27 | x11_joystick.c x11_monitor.c x11_time.c x11_window.c 28 | x11_unicode.c) 29 | endif() 30 | 31 | if (_GLFW_EGL) 32 | list(APPEND glfw_HEADERS ${common_HEADERS} egl_platform.h) 33 | list(APPEND glfw_SOURCES ${common_SOURCES} egl_context.c) 34 | elseif (_GLFW_NSGL) 35 | list(APPEND glfw_HEADERS ${common_HEADERS} nsgl_platform.h) 36 | list(APPEND glfw_SOURCES ${common_SOURCES} nsgl_context.m) 37 | elseif (_GLFW_WGL) 38 | list(APPEND glfw_HEADERS ${common_HEADERS} wgl_platform.h) 39 | list(APPEND glfw_SOURCES ${common_SOURCES} wgl_context.c) 40 | elseif (_GLFW_X11) 41 | list(APPEND glfw_HEADERS ${common_HEADERS} glx_platform.h) 42 | list(APPEND glfw_SOURCES ${common_SOURCES} glx_context.c) 43 | endif() 44 | 45 | if (APPLE) 46 | # For some reason, CMake doesn't know about .m 47 | set_source_files_properties(${glfw_SOURCES} PROPERTIES LANGUAGE C) 48 | endif() 49 | 50 | add_library(glfw ${glfw_SOURCES} ${glfw_HEADERS}) 51 | set_target_properties(glfw PROPERTIES OUTPUT_NAME "${GLFW_LIB_NAME}") 52 | 53 | if (BUILD_SHARED_LIBS) 54 | # Include version information in the output 55 | set_target_properties(glfw PROPERTIES VERSION ${GLFW_VERSION}) 56 | if (UNIX) 57 | set_target_properties(glfw PROPERTIES SOVERSION ${GLFW_VERSION_MAJOR}) 58 | endif() 59 | 60 | if (WIN32) 61 | # The GLFW DLL needs a special compile-time macro and import library name 62 | set_target_properties(glfw PROPERTIES PREFIX "" IMPORT_PREFIX "") 63 | 64 | if (MINGW) 65 | set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.a") 66 | else() 67 | set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.lib") 68 | endif() 69 | elseif (APPLE) 70 | # Append -fno-common to the compile flags to work around a bug in 71 | # Apple's GCC 72 | get_target_property(glfw_CFLAGS glfw COMPILE_FLAGS) 73 | if (NOT glfw_CFLAGS) 74 | set(glfw_CFLAGS "") 75 | endif() 76 | set_target_properties(glfw PROPERTIES 77 | COMPILE_FLAGS "${glfw_CFLAGS} -fno-common") 78 | endif() 79 | 80 | target_link_libraries(glfw ${glfw_LIBRARIES}) 81 | target_link_libraries(glfw LINK_INTERFACE_LIBRARIES) 82 | endif() 83 | 84 | if (GLFW_INSTALL) 85 | install(TARGETS glfw EXPORT glfwTargets DESTINATION lib${LIB_SUFFIX}) 86 | endif() 87 | 88 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | PROJECT(MTCL) 2 | 3 | ## Let's use a reasonable modern version 4 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12) 5 | SET(CMAKE_HAS_SORT 1) 6 | SET(CMAKE_MODULE_PATH 7 | ${MTCL_SOURCE_DIR}/CMake 8 | ${CMAKE_MODULE_PATH} 9 | ) 10 | 11 | ## Disallow in-source builds 12 | INCLUDE(OutOfSourceBuild) 13 | 14 | ## Set version and info 15 | SET(MTCL_MAJOR_VERSION 1) 16 | SET(MTCL_MINOR_VERSION 0) 17 | SET(MTCL_PATCH_VERSION 0) 18 | 19 | SET(MTCL_PACKAGE "Maratis Tiny C Library") 20 | SET(MTCL_VENDOR "Anael Seghezzi") 21 | SET(MTCL_VERSION "${MTCL_MAJOR_VERSION}.${MTCL_MINOR_VERSION}.${MTCL_PATCH_VERSION}") 22 | SET(MTCL_COPYRIGHT "Copyright (c) 2015, ${MTCL_VENDOR}.") 23 | 24 | MESSAGE(STATUS "${MTCL_PACKAGE} ${MTCL_VERSION}") 25 | 26 | ## Set install path 27 | SET(MTCL_INSTALL_DIR MTCL) 28 | 29 | IF(WIN32) 30 | FIND_PACKAGE(OpenGL REQUIRED) 31 | SET(MTCL_BUILD_FLAGS "") 32 | SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MOE_BUILD_FLAGS} /EHsc /nologo /GR /FC /DWIN32 /D_MBCS") 33 | SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /Z7 /W4 /Od /MDd /D_DEBUG /D__Debug__") 34 | SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /W1 /Ox /Ot /MD /DNDEBUG") 35 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MARATIS_BUILD_FLAGS} /EHsc /nologo /GR /FC /DWIN32 /D_MBCS") 36 | SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Z7 /W4 /Od /MDd /D_DEBUG /D__Debug__") 37 | SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /W1 /Ox /Ot /MD /DNDEBUG") 38 | SET(OS_SPECIFIC_LIBRARIES) 39 | ENDIF(WIN32) 40 | 41 | IF(APPLE) 42 | FIND_PACKAGE(OpenGL REQUIRED) 43 | FIND_LIBRARY(COCOA_LIB Cocoa) 44 | FIND_LIBRARY(CORE_SERVICES_LIB CoreServices) 45 | FIND_LIBRARY(FOUNDATION_LIB Foundation) 46 | FIND_LIBRARY(IOKIT_LIB IOKit) 47 | SET(MTCL_BUILD_FLAGS "-mmacosx-version-min=10.6") 48 | SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MTCL_BUILD_FLAGS} -O3 -DOSX") 49 | SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D__Debug__") 50 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MTCL_BUILD_FLAGS} -O3 -DOSX") 51 | SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D__Debug__") 52 | SET(CMAKE_SHARED_LINKER_FLAGS "-Wl") 53 | SET(OS_SPECIFIC_LIBRARIES ${COCOA_LIB} ${CORE_SERVICES_LIB} ${FOUNDATION_LIB} ${IOKIT_LIB}) 54 | ENDIF(APPLE) 55 | 56 | IF(UNIX AND NOT APPLE) 57 | FIND_PACKAGE(OpenGL REQUIRED) 58 | SET(MTCL_BUILD_FLAGS "") 59 | SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MTCL_BUILD_FLAGS} -O3 -fPIC -DLINUX -ldl") 60 | SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D__Debug__") 61 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MTCL_BUILD_FLAGS} -O3 -fPIC -DLINUX -ldl") 62 | SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D__Debug__") 63 | SET(CMAKE_SHARED_LINKER_FLAGS "-ldl -Wl,--as-needed,--allow-multiple-definition,--build-id") 64 | SET(OS_SPECIFIC_LIBRARIES pthread Xxf86vm X11 Xrandr Xi dl m) 65 | ENDIF(UNIX AND NOT APPLE) 66 | 67 | FIND_PACKAGE(OpenMP) 68 | IF(OPENMP_FOUND) 69 | SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") 70 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") 71 | ENDIF() 72 | 73 | ## Set up 3rd party dependencies 74 | SET(GLFW_INCLUDE_DIR ${MTCL_SOURCE_DIR}/tests/3rdparty/glfw/include) 75 | SET(TINYCTHREAD_INCLUDE_DIR ${MTCL_SOURCE_DIR}/tests/3rdparty/tinycthread/source) 76 | SET(STB_INCLUDE_DIR ${MTCL_SOURCE_DIR}/tests/3rdparty/stb) 77 | SET(GLFW_LIBRARIES glfw) 78 | SET(TINYCTHREAD_LIBRARIES tinycthread) 79 | 80 | ## Set up SDK dependencies 81 | SET(MTCL_INCLUDE_DIR ${MTCL_SOURCE_DIR}/include) 82 | 83 | ## Set up subdirectories... 84 | ADD_SUBDIRECTORY(tests/3rdparty) 85 | ADD_SUBDIRECTORY(tests/raster) 86 | ADD_SUBDIRECTORY(tests/raytracing) 87 | ADD_SUBDIRECTORY(tests/voronoi) 88 | ADD_SUBDIRECTORY(tests/vorogen) -------------------------------------------------------------------------------- /tests/3rdparty/glfw/src/config.h.in: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW - An OpenGL library 3 | // Platform: Any 4 | // API version: 3.0 5 | // WWW: http://www.glfw.org/ 6 | //------------------------------------------------------------------------ 7 | // Copyright (c) 2010 Camilla Berglund 8 | // 9 | // This software is provided 'as-is', without any express or implied 10 | // warranty. In no event will the authors be held liable for any damages 11 | // arising from the use of this software. 12 | // 13 | // Permission is granted to anyone to use this software for any purpose, 14 | // including commercial applications, and to alter it and redistribute it 15 | // freely, subject to the following restrictions: 16 | // 17 | // 1. The origin of this software must not be misrepresented; you must not 18 | // claim that you wrote the original software. If you use this software 19 | // in a product, an acknowledgment in the product documentation would 20 | // be appreciated but is not required. 21 | // 22 | // 2. Altered source versions must be plainly marked as such, and must not 23 | // be misrepresented as being the original software. 24 | // 25 | // 3. This notice may not be removed or altered from any source 26 | // distribution. 27 | // 28 | //======================================================================== 29 | // As config.h.in, this file is used by CMake to produce the config.h shared 30 | // configuration header file. If you are adding a feature requiring 31 | // conditional compilation, this is the proper place to add the macros. 32 | //======================================================================== 33 | // As config.h, this file defines compile-time build options and macros for 34 | // all platforms supported by GLFW. As this is a generated file, don't modify 35 | // it. Instead, you should modify the config.h.in file. 36 | //======================================================================== 37 | 38 | // Define this to 1 if building GLFW for X11 39 | #cmakedefine _GLFW_X11 40 | // Define this to 1 if building GLFW for Win32 41 | #cmakedefine _GLFW_WIN32 42 | // Define this to 1 if building GLFW for Cocoa 43 | #cmakedefine _GLFW_COCOA 44 | 45 | // Define this to 1 if building GLFW for EGL 46 | #cmakedefine _GLFW_EGL 47 | // Define this to 1 if building GLFW for GLX 48 | #cmakedefine _GLFW_GLX 49 | // Define this to 1 if building GLFW for WGL 50 | #cmakedefine _GLFW_WGL 51 | // Define this to 1 if building GLFW for NSGL 52 | #cmakedefine _GLFW_NSGL 53 | 54 | // Define this to 1 if building as a shared library / dynamic library / DLL 55 | #cmakedefine _GLFW_BUILD_DLL 56 | 57 | // Define this to 1 to disable dynamic loading of winmm 58 | #cmakedefine _GLFW_NO_DLOAD_WINMM 59 | 60 | // Define this to 1 if glXGetProcAddress is available 61 | #cmakedefine _GLFW_HAS_GLXGETPROCADDRESS 62 | // Define this to 1 if glXGetProcAddressARB is available 63 | #cmakedefine _GLFW_HAS_GLXGETPROCADDRESSARB 64 | // Define this to 1 if glXGetProcAddressEXT is available 65 | #cmakedefine _GLFW_HAS_GLXGETPROCADDRESSEXT 66 | // Define this to 1 if dlopen is available 67 | #cmakedefine _GLFW_HAS_DLOPEN 68 | 69 | // Define this to 1 if glfwInit should change the current directory 70 | #cmakedefine _GLFW_USE_CHDIR 71 | // Define this to 1 if glfwCreateWindow should populate the menu bar 72 | #cmakedefine _GLFW_USE_MENUBAR 73 | 74 | // Define this to 1 if using OpenGL as the client library 75 | #cmakedefine _GLFW_USE_OPENGL 76 | // Define this to 1 if using OpenGL ES 1.1 as the client library 77 | #cmakedefine _GLFW_USE_GLESV1 78 | // Define this to 1 if using OpenGL ES 2.0 as the client library 79 | #cmakedefine _GLFW_USE_GLESV2 80 | 81 | // The GLFW version as used by glfwGetVersionString 82 | #define _GLFW_VERSION_FULL "@GLFW_VERSION_FULL@" 83 | 84 | -------------------------------------------------------------------------------- /tests/raster/main.c: -------------------------------------------------------------------------------- 1 | /*====================================================================== 2 | Maratis Tiny C Library 3 | version 1.0 4 | ------------------------------------------------------------------------ 5 | Copyright (c) 2015 Anael Seghezzi 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 | /* software rasterization test */ 29 | 30 | #define M_MATH_IMPLEMENTATION 31 | #define M_IMAGE_IMPLEMENTATION 32 | #define M_RASTER_IMPLEMENTATION 33 | #include 34 | #include 35 | #include 36 | 37 | #include "../test.h" 38 | 39 | static struct m_image test_buffer = M_IMAGE_IDENTITY(); 40 | 41 | float3 vertices[8] = { 42 | {-1, -1, -1}, 43 | { 1, -1, -1}, 44 | { 1, 1, -1}, 45 | {-1, 1, -1}, 46 | {-1, -1, 1}, 47 | { 1, -1, 1}, 48 | { 1, 1, 1}, 49 | {-1, 1, 1} 50 | }; 51 | 52 | void draw(void) 53 | { 54 | float2 pr[8]; 55 | float3 pos; 56 | float color[3] = {1, 1, 1}; 57 | float *data; 58 | int i; 59 | 60 | /* move */ 61 | pos.x = sinf(test_t * 0.025f); 62 | pos.y = sinf(test_t * 0.02f) * 0.25f; 63 | pos.z = 5 + sinf(test_t * 0.035f) * 2.0f; 64 | 65 | /* projection */ 66 | for (i = 0; i < 8; i++) { 67 | float3 v; float iz; 68 | 69 | M_ADD3(v, pos, vertices[i]); 70 | iz = 1.0f / v.z; 71 | 72 | pr[i].x = ((v.x * iz) + 0.5f) * test_buffer.width; 73 | pr[i].y = ((v.y * iz) + 0.5f) * test_buffer.height; 74 | } 75 | 76 | /* clear */ 77 | memset(test_buffer.data, 0, test_buffer.size * sizeof(float)); 78 | 79 | /* draw lines */ 80 | for (i = 0; i < 4; i++) { 81 | int i2 = i == 3 ? 0 : i + 1; 82 | m_raster_line((float *)test_buffer.data, test_buffer.width, test_buffer.height, test_buffer.comp, &pr[i].x, &pr[i2].x, color); 83 | } 84 | for (i = 4; i < 8; i++) { 85 | int i2 = i == 7 ? 4 : i + 1; 86 | m_raster_line((float *)test_buffer.data, test_buffer.width, test_buffer.height, test_buffer.comp, &pr[i].x, &pr[i2].x, color); 87 | } 88 | for (i = 0; i < 4; i++) { 89 | int i2 = i + 4; 90 | m_raster_line((float *)test_buffer.data, test_buffer.width, test_buffer.height, test_buffer.comp, &pr[i].x, &pr[i2].x, color); 91 | } 92 | 93 | /* add some noise */ 94 | data = (float *)test_buffer.data; 95 | for (i = 0; i < test_buffer.size; i++) { 96 | data[i] += ((float)rand() / (float)RAND_MAX) * 0.25f; 97 | } 98 | } 99 | 100 | void main_loop(void) 101 | { 102 | draw(); 103 | test_swap_buffer(&test_buffer); 104 | test_update(); 105 | } 106 | 107 | int main(int argc, char **argv) 108 | { 109 | if (! test_create("M - RasterToy", 256, 256)) 110 | return EXIT_FAILURE; 111 | 112 | m_image_create(&test_buffer, M_FLOAT, 256, 256, 3); 113 | 114 | #ifdef __EMSCRIPTEN__ 115 | emscripten_set_main_loop(main_loop, 0, 1); 116 | #else 117 | while (test_state) { 118 | main_loop(); 119 | thrd_yield(); 120 | } 121 | #endif 122 | 123 | m_image_destroy(&test_buffer); 124 | test_destroy(); 125 | return EXIT_SUCCESS; 126 | } 127 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/src/wgl_platform.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW - An OpenGL library 3 | // Platform: WGL 4 | // API version: 3.0 5 | // WWW: http://www.glfw.org/ 6 | //------------------------------------------------------------------------ 7 | // Copyright (c) 2002-2006 Marcus Geelnard 8 | // Copyright (c) 2006-2010 Camilla Berglund 9 | // 10 | // This software is provided 'as-is', without any express or implied 11 | // warranty. In no event will the authors be held liable for any damages 12 | // arising from the use of this software. 13 | // 14 | // Permission is granted to anyone to use this software for any purpose, 15 | // including commercial applications, and to alter it and redistribute it 16 | // freely, subject to the following restrictions: 17 | // 18 | // 1. The origin of this software must not be misrepresented; you must not 19 | // claim that you wrote the original software. If you use this software 20 | // in a product, an acknowledgment in the product documentation would 21 | // be appreciated but is not required. 22 | // 23 | // 2. Altered source versions must be plainly marked as such, and must not 24 | // be misrepresented as being the original software. 25 | // 26 | // 3. This notice may not be removed or altered from any source 27 | // distribution. 28 | // 29 | //======================================================================== 30 | 31 | #ifndef _wgl_platform_h_ 32 | #define _wgl_platform_h_ 33 | 34 | // This path may need to be changed if you build GLFW using your own setup 35 | // We ship and use our own copy of wglext.h since GLFW uses fairly new 36 | // extensions and not all operating systems come with an up-to-date version 37 | #include "../deps/GL/wglext.h" 38 | 39 | 40 | #define _GLFW_PLATFORM_FBCONFIG int wgl 41 | #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextWGL wgl 42 | #define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryWGL wgl 43 | 44 | 45 | //======================================================================== 46 | // GLFW platform specific types 47 | //======================================================================== 48 | 49 | //------------------------------------------------------------------------ 50 | // Platform-specific OpenGL context structure 51 | //------------------------------------------------------------------------ 52 | typedef struct _GLFWcontextWGL 53 | { 54 | // Platform specific window resources 55 | HDC dc; // Private GDI device context 56 | HGLRC context; // Permanent rendering context 57 | 58 | // Platform specific extensions (context specific) 59 | PFNWGLSWAPINTERVALEXTPROC SwapIntervalEXT; 60 | PFNWGLGETPIXELFORMATATTRIBIVARBPROC GetPixelFormatAttribivARB; 61 | PFNWGLGETEXTENSIONSSTRINGEXTPROC GetExtensionsStringEXT; 62 | PFNWGLGETEXTENSIONSSTRINGARBPROC GetExtensionsStringARB; 63 | PFNWGLCREATECONTEXTATTRIBSARBPROC CreateContextAttribsARB; 64 | GLboolean EXT_swap_control; 65 | GLboolean ARB_multisample; 66 | GLboolean ARB_framebuffer_sRGB; 67 | GLboolean ARB_pixel_format; 68 | GLboolean ARB_create_context; 69 | GLboolean ARB_create_context_profile; 70 | GLboolean EXT_create_context_es2_profile; 71 | GLboolean ARB_create_context_robustness; 72 | } _GLFWcontextWGL; 73 | 74 | 75 | //------------------------------------------------------------------------ 76 | // Platform-specific library global data for WGL 77 | //------------------------------------------------------------------------ 78 | typedef struct _GLFWlibraryWGL 79 | { 80 | GLboolean hasTLS; 81 | DWORD current; 82 | 83 | } _GLFWlibraryWGL; 84 | 85 | 86 | #endif // _wgl_platform_h_ 87 | -------------------------------------------------------------------------------- /include/m_path_finding.h: -------------------------------------------------------------------------------- 1 | /*====================================================================== 2 | Maratis Tiny C Library 3 | version 1.0 4 | ------------------------------------------------------------------------ 5 | Copyright (c) 2016 Anael Seghezzi 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 | Floodfill-based path finding: 29 | 30 | to create the implementation, 31 | #define M_PF_IMPLEMENTATION 32 | in *one* C/CPP file that includes this file. 33 | */ 34 | 35 | #ifndef M_PF_H 36 | #define M_PF_H 37 | 38 | #define M_PF_VERSION 1 39 | 40 | #ifndef MPFAPI 41 | #ifdef __cplusplus 42 | #define MPFAPI extern "C" 43 | #else 44 | #define MPFAPI extern 45 | #endif 46 | #endif 47 | 48 | struct m_pf_point 49 | { 50 | unsigned short x, y; 51 | }; 52 | 53 | /* floodfill a score map from destination (x, y) 54 | the input map is filled with this two values: 0 = ground, UINT_MAX = wall 55 | *stack should be at least of size (w * h) */ 56 | MPFAPI void m_pf_floodfill(unsigned int *map, int w, int h, int x, int y, struct m_pf_point *stack); 57 | 58 | /* backtrace a path from start (x, y) */ 59 | MPFAPI int m_pf_backtrace(struct m_pf_point *dest, const unsigned int *map, int w, int h, int x, int y); 60 | 61 | #endif /* M_PF_H */ 62 | 63 | #ifdef M_PF_IMPLEMENTATION 64 | 65 | #include 66 | 67 | #define M_PF_PUSH_PIXEL(x2, y2)\ 68 | if(map[w * (y2) + (x2)] == 0) {\ 69 | stack[stack_n].x = (x2);\ 70 | stack[stack_n].y = (y2);\ 71 | stack_n++;\ 72 | map[w * (y2) + (x2)] = i;\ 73 | } 74 | 75 | MPFAPI void m_pf_floodfill(unsigned int *map, int w, int h, int x, int y, struct m_pf_point *stack) 76 | { 77 | unsigned int i = 0; 78 | int stack_c = 0; 79 | int stack_n = 0; 80 | 81 | M_PF_PUSH_PIXEL(x, y) 82 | 83 | while (stack_c < stack_n) { 84 | 85 | x = stack[stack_c].x; 86 | y = stack[stack_c].y; 87 | i = map[w * y + x] + 1; 88 | stack_c++; 89 | 90 | if (y > 0) 91 | M_PF_PUSH_PIXEL(x, y - 1) 92 | if (x > 0) 93 | M_PF_PUSH_PIXEL(x - 1, y) 94 | if (x < (w - 1)) 95 | M_PF_PUSH_PIXEL(x + 1, y) 96 | if (y < (h - 1)) 97 | M_PF_PUSH_PIXEL(x, y + 1) 98 | } 99 | } 100 | 101 | MPFAPI int m_pf_backtrace(struct m_pf_point *dest, const unsigned int *map, int w, int h, int x, int y) 102 | { 103 | const unsigned int *p = map + (y * w + x); 104 | int i, s = w * h; 105 | 106 | if (*p == 0 || *p == UINT_MAX) 107 | return 0; 108 | 109 | for (i = 0; i < s; i++) { 110 | 111 | unsigned int min = UINT_MAX; 112 | int minx, miny; 113 | int maxx, maxy; 114 | int xi, yi; 115 | 116 | minx = (x - 1) < 0 ? 0 : (x - 1); 117 | miny = (y - 1) < 0 ? 0 : (y - 1); 118 | maxx = (x + 2) > w ? w : (x + 2); 119 | maxy = (y + 2) > h ? h : (y + 2); 120 | 121 | for (yi = miny; yi < maxy; yi++) { 122 | p = map + (yi * w + minx); 123 | for (xi = minx; xi < maxx; xi++) { 124 | 125 | if (*p < min) { 126 | min = *p; 127 | y = yi; 128 | x = xi; 129 | } 130 | p++; 131 | } 132 | } 133 | 134 | dest[i].x = x; 135 | dest[i].y = y; 136 | 137 | if (min == 1) 138 | return i + 1; 139 | } 140 | 141 | return 0; 142 | } 143 | 144 | #undef M_PF_PUSH_PIXEL 145 | 146 | #endif /* M_PF_IMPLEMENTATION */ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Maratis Tiny C library 2 | ====================== 3 | 4 | is a collection of small and efficient math and image processing routines written in ANSI C with no dependencies. 5 | 6 | The library is divided in independent single files (stb style): 7 | - [m_math.h](https://github.com/anael-seghezzi/Maratis-Tiny-C-library/blob/master/include/m_math.h) 8 | - [m_image.h](https://github.com/anael-seghezzi/Maratis-Tiny-C-library/blob/master/include/m_image.h) 9 | - [m_raster.h](https://github.com/anael-seghezzi/Maratis-Tiny-C-library/blob/master/include/m_raster.h) 10 | - [m_dist.h](https://github.com/anael-seghezzi/Maratis-Tiny-C-library/blob/master/include/m_dist.h) 11 | - [m_path_finding.h](https://github.com/anael-seghezzi/Maratis-Tiny-C-library/blob/master/include/m_path_finding.h) 12 | 13 | Math 14 | ---- 15 | 16 | * vector manipulation 17 | * interpolation (cubic, catmullrom) 18 | * quaternion (basics, slerp...) 19 | * matrix (projection, transformation...) 20 | * random number generator 21 | * 2d routines 22 | * 3d routines 23 | * voxeliser (tri-box overlap) 24 | * raytracing (sphere, plane, box, triangle) 25 | 26 | Image manipulation 27 | ------------------ 28 | 29 | * ubyte, ushort, int, half, float... 30 | * copy, conversions, mirror, reframe, rotate... 31 | * filters (convolution, gaussian blur, sobel, harris) 32 | * resizing, pyrdown 33 | * morphology (floodfill, dilate, erode, thinning...) 34 | * corner detection (harris, non-maxima suppression) 35 | 36 | Rasterization 37 | ------------- 38 | 39 | * triangle with interpolation (perspective correct) 40 | * basic line, circle and polygon 41 | 42 | Distance map 43 | ------------ 44 | 45 | * distance transform and voronoi 46 | 47 | Path finding 48 | ------------ 49 | 50 | * path finding on regular grid (floodfill-based) 51 | 52 | Asm.js demos 53 | ------------ 54 | 55 | * [m_raster](http://maratis3d.org/js/m_raster/m_raster.html) 56 | * [m_voronoi](http://maratis3d.org/js/m_voronoi/m_voronoi.html) 57 | * [m_raytracing](http://maratis3d.org/js/m_raytracing/m_raytracing.html) 58 | 59 | Games / Demos 60 | ------------- 61 | 62 | * Back on Earth - Ludum Dare 34 Compo 63 | 64 | [![BackOnEarth](http://maratis3d.com/download/ludum34/scm.png)](http://maratis3d.com/download/ludum34/b/web_player.html) 65 | 66 | 67 | Building the demos (CMake) 68 | -------------------------- 69 | 70 | **Unix:** 71 | 72 | run: 73 | 74 | build_tests_unix.sh 75 | 76 | or type: 77 | 78 | mkdir Build 79 | cd Build 80 | cmake -G "Unix Makefiles" ../ -DCMAKE_INSTALL_PREFIX=../bin 81 | make 82 | make install 83 | 84 | **Windows:** 85 | 86 | mkdir Build 87 | cd Build 88 | cmake -G "Visual Studio 11" ../ -DCMAKE_INSTALL_PREFIX=../bin 89 | 90 | or: 91 | 92 | mkdir Build 93 | cd Build 94 | cmake -G "MinGW Makefiles" ../ -DCMAKE_INSTALL_PREFIX=../bin 95 | make 96 | make install 97 | 98 | **Emscripten:** 99 | 100 | ./emcc -s LEGACY_GL_EMULATION=1 -s USE_GLFW=3 101 | 102 | License (zlib) 103 | -------------- 104 | 105 | Copyright (c) 2015 Anael Seghezzi 106 | 107 | This software is provided 'as-is', without any express or implied 108 | warranty. In no event will the authors be held liable for any damages 109 | arising from the use of this software. 110 | 111 | Permission is granted to anyone to use this software for any purpose, 112 | including commercial applications, and to alter it and redistribute it 113 | freely, subject to the following restrictions: 114 | 115 | 1. The origin of this software must not be misrepresented; you must not 116 | claim that you wrote the original software. If you use this software 117 | in a product, an acknowledgment in the product documentation would 118 | be appreciated but is not required. 119 | 120 | 2. Altered source versions must be plainly marked as such, and must not 121 | be misrepresented as being the original software. 122 | 123 | 3. This notice may not be removed or altered from any source 124 | distribution. 125 | 126 | You may also like 127 | ----------------- 128 | 129 | * [stb](https://github.com/nothings/stb) 130 | * [PAL](https://github.com/parallella/pal) 131 | * [Maratis](http://www.maratis3d.org) 132 | * [BGFX](https://github.com/bkaradzic/bgfx) 133 | * [GLFW](https://github.com/glfw/glfw) 134 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/src/gamma.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW - An OpenGL library 3 | // Platform: Any 4 | // API version: 3.0 5 | // WWW: http://www.glfw.org/ 6 | //------------------------------------------------------------------------ 7 | // Copyright (c) 2010 Camilla Berglund 8 | // 9 | // This software is provided 'as-is', without any express or implied 10 | // warranty. In no event will the authors be held liable for any damages 11 | // arising from the use of this software. 12 | // 13 | // Permission is granted to anyone to use this software for any purpose, 14 | // including commercial applications, and to alter it and redistribute it 15 | // freely, subject to the following restrictions: 16 | // 17 | // 1. The origin of this software must not be misrepresented; you must not 18 | // claim that you wrote the original software. If you use this software 19 | // in a product, an acknowledgment in the product documentation would 20 | // be appreciated but is not required. 21 | // 22 | // 2. Altered source versions must be plainly marked as such, and must not 23 | // be misrepresented as being the original software. 24 | // 25 | // 3. This notice may not be removed or altered from any source 26 | // distribution. 27 | // 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #if defined(_MSC_VER) 37 | #include 38 | #endif 39 | 40 | 41 | ////////////////////////////////////////////////////////////////////////// 42 | ////// GLFW internal API ////// 43 | ////////////////////////////////////////////////////////////////////////// 44 | 45 | void _glfwAllocGammaRamp(GLFWgammaramp* ramp, unsigned int size) 46 | { 47 | ramp->red = (unsigned short*) malloc(size * sizeof(unsigned short)); 48 | ramp->green = (unsigned short*) malloc(size * sizeof(unsigned short)); 49 | ramp->blue = (unsigned short*) malloc(size * sizeof(unsigned short)); 50 | ramp->size = size; 51 | } 52 | 53 | void _glfwFreeGammaRamp(GLFWgammaramp* ramp) 54 | { 55 | free(ramp->red); 56 | free(ramp->green); 57 | free(ramp->blue); 58 | 59 | memset(ramp, 0, sizeof(GLFWgammaramp)); 60 | } 61 | 62 | 63 | ////////////////////////////////////////////////////////////////////////// 64 | ////// GLFW public API ////// 65 | ////////////////////////////////////////////////////////////////////////// 66 | 67 | GLFWAPI void glfwSetGamma(GLFWmonitor* handle, float gamma) 68 | { 69 | int i; 70 | unsigned short values[256]; 71 | GLFWgammaramp ramp; 72 | 73 | _GLFW_REQUIRE_INIT(); 74 | 75 | if (gamma <= 0.f) 76 | { 77 | _glfwInputError(GLFW_INVALID_VALUE, 78 | "Gamma value must be greater than zero"); 79 | return; 80 | } 81 | 82 | for (i = 0; i < 256; i++) 83 | { 84 | float value; 85 | 86 | // Calculate intensity 87 | value = i / 255.f; 88 | // Apply gamma curve 89 | value = (float) pow(value, 1.f / gamma) * 65535.f + 0.5f; 90 | 91 | // Clamp to value range 92 | if (value < 0.f) 93 | value = 0.f; 94 | else if (value > 65535.f) 95 | value = 65535.f; 96 | 97 | values[i] = (unsigned short) value; 98 | } 99 | 100 | ramp.red = values; 101 | ramp.green = values; 102 | ramp.blue = values; 103 | ramp.size = 256; 104 | 105 | glfwSetGammaRamp(handle, &ramp); 106 | } 107 | 108 | GLFWAPI const GLFWgammaramp* glfwGetGammaRamp(GLFWmonitor* handle) 109 | { 110 | _GLFWmonitor* monitor = (_GLFWmonitor*) handle; 111 | 112 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 113 | 114 | _glfwFreeGammaRamp(&monitor->currentRamp); 115 | _glfwPlatformGetGammaRamp(monitor, &monitor->currentRamp); 116 | 117 | return &monitor->currentRamp; 118 | } 119 | 120 | GLFWAPI void glfwSetGammaRamp(GLFWmonitor* handle, const GLFWgammaramp* ramp) 121 | { 122 | _GLFWmonitor* monitor = (_GLFWmonitor*) handle; 123 | 124 | _GLFW_REQUIRE_INIT(); 125 | 126 | if (!monitor->originalRamp.size) 127 | _glfwPlatformGetGammaRamp(monitor, &monitor->originalRamp); 128 | 129 | _glfwPlatformSetGammaRamp(monitor, ramp); 130 | } 131 | 132 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/src/win32_clipboard.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW - An OpenGL library 3 | // Platform: Win32 4 | // API version: 3.0 5 | // WWW: http://www.glfw.org/ 6 | //------------------------------------------------------------------------ 7 | // Copyright (c) 2010 Camilla Berglund 8 | // 9 | // This software is provided 'as-is', without any express or implied 10 | // warranty. In no event will the authors be held liable for any damages 11 | // arising from the use of this software. 12 | // 13 | // Permission is granted to anyone to use this software for any purpose, 14 | // including commercial applications, and to alter it and redistribute it 15 | // freely, subject to the following restrictions: 16 | // 17 | // 1. The origin of this software must not be misrepresented; you must not 18 | // claim that you wrote the original software. If you use this software 19 | // in a product, an acknowledgment in the product documentation would 20 | // be appreciated but is not required. 21 | // 22 | // 2. Altered source versions must be plainly marked as such, and must not 23 | // be misrepresented as being the original software. 24 | // 25 | // 3. This notice may not be removed or altered from any source 26 | // distribution. 27 | // 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | 38 | ////////////////////////////////////////////////////////////////////////// 39 | ////// GLFW platform API ////// 40 | ////////////////////////////////////////////////////////////////////////// 41 | 42 | void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) 43 | { 44 | WCHAR* wideString; 45 | HANDLE stringHandle; 46 | size_t wideSize; 47 | 48 | wideString = _glfwCreateWideStringFromUTF8(string); 49 | if (!wideString) 50 | { 51 | _glfwInputError(GLFW_PLATFORM_ERROR, 52 | "Win32: Failed to convert clipboard string to " 53 | "wide string"); 54 | return; 55 | } 56 | 57 | wideSize = (wcslen(wideString) + 1) * sizeof(WCHAR); 58 | 59 | stringHandle = GlobalAlloc(GMEM_MOVEABLE, wideSize); 60 | if (!stringHandle) 61 | { 62 | free(wideString); 63 | 64 | _glfwInputError(GLFW_PLATFORM_ERROR, 65 | "Win32: Failed to allocate global handle for clipboard"); 66 | return; 67 | } 68 | 69 | memcpy(GlobalLock(stringHandle), wideString, wideSize); 70 | GlobalUnlock(stringHandle); 71 | 72 | if (!OpenClipboard(window->win32.handle)) 73 | { 74 | GlobalFree(stringHandle); 75 | free(wideString); 76 | 77 | _glfwInputError(GLFW_PLATFORM_ERROR, "Win32: Failed to open clipboard"); 78 | return; 79 | } 80 | 81 | EmptyClipboard(); 82 | SetClipboardData(CF_UNICODETEXT, stringHandle); 83 | CloseClipboard(); 84 | 85 | free(wideString); 86 | } 87 | 88 | const char* _glfwPlatformGetClipboardString(_GLFWwindow* window) 89 | { 90 | HANDLE stringHandle; 91 | 92 | if (!IsClipboardFormatAvailable(CF_UNICODETEXT)) 93 | { 94 | _glfwInputError(GLFW_FORMAT_UNAVAILABLE, NULL); 95 | return NULL; 96 | } 97 | 98 | if (!OpenClipboard(window->win32.handle)) 99 | { 100 | _glfwInputError(GLFW_PLATFORM_ERROR, "Win32: Failed to open clipboard"); 101 | return NULL; 102 | } 103 | 104 | stringHandle = GetClipboardData(CF_UNICODETEXT); 105 | if (!stringHandle) 106 | { 107 | CloseClipboard(); 108 | 109 | _glfwInputError(GLFW_PLATFORM_ERROR, 110 | "Win32: Failed to retrieve clipboard data"); 111 | return NULL; 112 | } 113 | 114 | free(_glfw.win32.clipboardString); 115 | _glfw.win32.clipboardString = 116 | _glfwCreateUTF8FromWideString(GlobalLock(stringHandle)); 117 | 118 | GlobalUnlock(stringHandle); 119 | CloseClipboard(); 120 | 121 | if (!_glfw.win32.clipboardString) 122 | { 123 | _glfwInputError(GLFW_PLATFORM_ERROR, 124 | "Win32: Failed to convert wide string to UTF-8"); 125 | return NULL; 126 | } 127 | 128 | return _glfw.win32.clipboardString; 129 | } 130 | 131 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/src/cocoa_init.m: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW - An OpenGL library 3 | // Platform: Cocoa/NSOpenGL 4 | // API Version: 3.0 5 | // WWW: http://www.glfw.org/ 6 | //------------------------------------------------------------------------ 7 | // Copyright (c) 2009-2010 Camilla Berglund 8 | // 9 | // This software is provided 'as-is', without any express or implied 10 | // warranty. In no event will the authors be held liable for any damages 11 | // arising from the use of this software. 12 | // 13 | // Permission is granted to anyone to use this software for any purpose, 14 | // including commercial applications, and to alter it and redistribute it 15 | // freely, subject to the following restrictions: 16 | // 17 | // 1. The origin of this software must not be misrepresented; you must not 18 | // claim that you wrote the original software. If you use this software 19 | // in a product, an acknowledgment in the product documentation would 20 | // be appreciated but is not required. 21 | // 22 | // 2. Altered source versions must be plainly marked as such, and must not 23 | // be misrepresented as being the original software. 24 | // 25 | // 3. This notice may not be removed or altered from any source 26 | // distribution. 27 | // 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | #include // For MAXPATHLEN 32 | 33 | 34 | #if defined(_GLFW_USE_CHDIR) 35 | 36 | // Change to our application bundle's resources directory, if present 37 | // 38 | static void changeToResourcesDirectory(void) 39 | { 40 | char resourcesPath[MAXPATHLEN]; 41 | 42 | CFBundleRef bundle = CFBundleGetMainBundle(); 43 | if (!bundle) 44 | return; 45 | 46 | CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(bundle); 47 | 48 | CFStringRef last = CFURLCopyLastPathComponent(resourcesURL); 49 | if (CFStringCompare(CFSTR("Resources"), last, 0) != kCFCompareEqualTo) 50 | { 51 | CFRelease(last); 52 | CFRelease(resourcesURL); 53 | return; 54 | } 55 | 56 | CFRelease(last); 57 | 58 | if (!CFURLGetFileSystemRepresentation(resourcesURL, 59 | true, 60 | (UInt8*) resourcesPath, 61 | MAXPATHLEN)) 62 | { 63 | CFRelease(resourcesURL); 64 | return; 65 | } 66 | 67 | CFRelease(resourcesURL); 68 | 69 | chdir(resourcesPath); 70 | } 71 | 72 | #endif /* _GLFW_USE_CHDIR */ 73 | 74 | 75 | ////////////////////////////////////////////////////////////////////////// 76 | ////// GLFW platform API ////// 77 | ////////////////////////////////////////////////////////////////////////// 78 | 79 | int _glfwPlatformInit(void) 80 | { 81 | _glfw.ns.autoreleasePool = [[NSAutoreleasePool alloc] init]; 82 | 83 | #if defined(_GLFW_USE_CHDIR) 84 | changeToResourcesDirectory(); 85 | #endif 86 | 87 | _glfwInitTimer(); 88 | 89 | _glfwInitJoysticks(); 90 | 91 | if (!_glfwInitContextAPI()) 92 | return GL_FALSE; 93 | 94 | _glfw.ns.eventSource = CGEventSourceCreate(kCGEventSourceStateHIDSystemState); 95 | if (!_glfw.ns.eventSource) 96 | return GL_FALSE; 97 | 98 | CGEventSourceSetLocalEventsSuppressionInterval(_glfw.ns.eventSource, 0.0); 99 | 100 | return GL_TRUE; 101 | } 102 | 103 | void _glfwPlatformTerminate(void) 104 | { 105 | if (_glfw.ns.eventSource) 106 | { 107 | CFRelease(_glfw.ns.eventSource); 108 | _glfw.ns.eventSource = NULL; 109 | } 110 | 111 | [NSApp setDelegate:nil]; 112 | [_glfw.ns.delegate release]; 113 | _glfw.ns.delegate = nil; 114 | 115 | [_glfw.ns.autoreleasePool release]; 116 | _glfw.ns.autoreleasePool = nil; 117 | 118 | [_glfw.ns.cursor release]; 119 | _glfw.ns.cursor = nil; 120 | 121 | _glfwTerminateJoysticks(); 122 | 123 | _glfwTerminateContextAPI(); 124 | } 125 | 126 | const char* _glfwPlatformGetVersionString(void) 127 | { 128 | const char* version = _GLFW_VERSION_FULL " Cocoa" 129 | #if defined(_GLFW_NSGL) 130 | " NSGL" 131 | #endif 132 | #if defined(_GLFW_USE_CHDIR) 133 | " chdir" 134 | #endif 135 | #if defined(_GLFW_USE_MENUBAR) 136 | " menubar" 137 | #endif 138 | #if defined(_GLFW_BUILD_DLL) 139 | " dynamic" 140 | #endif 141 | ; 142 | 143 | return version; 144 | } 145 | 146 | -------------------------------------------------------------------------------- /tests/voronoi/main.c: -------------------------------------------------------------------------------- 1 | /*====================================================================== 2 | Maratis Tiny C Library 3 | version 1.0 4 | ------------------------------------------------------------------------ 5 | Copyright (c) 2015 Anael Seghezzi 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 | /* voronoi test */ 29 | 30 | #define M_MATH_IMPLEMENTATION 31 | #define M_IMAGE_IMPLEMENTATION 32 | #define M_DIST_IMPLEMENTATION 33 | #include 34 | #include 35 | #include 36 | 37 | #include "../test.h" 38 | 39 | #define POINT_COUNT 64 40 | #define RANDF ((float)rand() / (float)RAND_MAX) 41 | 42 | struct test_point 43 | { 44 | float2 pos; 45 | float2 dir; 46 | float3 col; 47 | }; 48 | 49 | static struct m_image test_buffer = M_IMAGE_IDENTITY(); 50 | static struct test_point points[POINT_COUNT]; 51 | static struct m_image tmp_buffer = M_IMAGE_IDENTITY(); 52 | static struct m_image tmpi = M_IMAGE_IDENTITY(); 53 | 54 | 55 | static void init(void) 56 | { 57 | int i; 58 | for (i = 0; i < POINT_COUNT; i++) { 59 | points[i].pos.x = RANDF; 60 | points[i].pos.y = RANDF; 61 | points[i].dir.x = RANDF - 0.5f; 62 | points[i].dir.y = RANDF - 0.5f; 63 | points[i].col.x = RANDF; 64 | points[i].col.y = RANDF; 65 | points[i].col.z = RANDF; 66 | } 67 | } 68 | 69 | static void clear(void) 70 | { 71 | m_image_destroy(&tmp_buffer); 72 | m_image_destroy(&tmpi); 73 | } 74 | 75 | static void animate(void) 76 | { 77 | int i; 78 | for (i = 0; i < POINT_COUNT; i++) { 79 | 80 | /* move point */ 81 | points[i].pos.x += points[i].dir.x * 0.01f; 82 | points[i].pos.y += points[i].dir.y * 0.01f; 83 | 84 | /* bounce x */ 85 | if (points[i].pos.x > 1) { 86 | points[i].pos.x = 1; 87 | points[i].dir.x = -points[i].dir.x; 88 | } 89 | else if (points[i].pos.x < 0) { 90 | points[i].pos.x = 0; 91 | points[i].dir.x = -points[i].dir.x; 92 | } 93 | 94 | /* bounce y */ 95 | if (points[i].pos.y > 1) { 96 | points[i].pos.y = 1; 97 | points[i].dir.y = -points[i].dir.y; 98 | } 99 | else if (points[i].pos.y < 0) { 100 | points[i].pos.y = 0; 101 | points[i].dir.y = -points[i].dir.y; 102 | } 103 | } 104 | } 105 | 106 | static void draw(void) 107 | { 108 | float *tmp_data; 109 | float *test_data; 110 | int w = test_buffer.width; 111 | int h = test_buffer.height; 112 | int size = w * h; 113 | int i; 114 | 115 | m_image_create(&tmp_buffer, M_FLOAT, w, h, 1); 116 | tmp_data = (float *)tmp_buffer.data; 117 | 118 | for (i = 0; i < size; i++) 119 | tmp_data[i] = M_DIST_MAX; 120 | 121 | for (i = 0; i < POINT_COUNT; i++) { 122 | 123 | /* draw point */ 124 | int x = (int)(points[i].pos.x * (w - 1)); 125 | int y = (int)(points[i].pos.y * (h - 1)); 126 | 127 | /* mask */ 128 | tmp_data[y * w + x] = 0; 129 | 130 | /* color */ 131 | test_data = (float *)test_buffer.data + (y * w + x) * test_buffer.comp; 132 | test_data[0] = points[i].col.x; 133 | test_data[1] = points[i].col.y; 134 | test_data[2] = points[i].col.z; 135 | } 136 | 137 | m_image_voronoi_transform(&tmp_buffer, &tmpi, &tmp_buffer); 138 | m_image_voronoi_fill(&test_buffer, &test_buffer, &tmpi); 139 | } 140 | 141 | void main_loop(void) 142 | { 143 | animate(); 144 | draw(); 145 | test_swap_buffer(&test_buffer); 146 | test_update(); 147 | } 148 | 149 | int main(int argc, char **argv) 150 | { 151 | if (! test_create("M - VoronoiTest", 256, 256)) 152 | return EXIT_FAILURE; 153 | 154 | m_image_create(&test_buffer, M_FLOAT, 256, 256, 3); 155 | init(); 156 | 157 | #ifdef __EMSCRIPTEN__ 158 | emscripten_set_main_loop(main_loop, 0, 1); 159 | #else 160 | while (test_state) { 161 | main_loop(); 162 | thrd_yield(); 163 | } 164 | #endif 165 | 166 | m_image_destroy(&test_buffer); 167 | clear(); 168 | test_destroy(); 169 | return EXIT_SUCCESS; 170 | } 171 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/src/cocoa_platform.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW - An OpenGL library 3 | // Platform: Cocoa 4 | // API Version: 3.0 5 | // WWW: http://www.glfw.org/ 6 | //------------------------------------------------------------------------ 7 | // Copyright (c) 2009-2010 Camilla Berglund 8 | // 9 | // This software is provided 'as-is', without any express or implied 10 | // warranty. In no event will the authors be held liable for any damages 11 | // arising from the use of this software. 12 | // 13 | // Permission is granted to anyone to use this software for any purpose, 14 | // including commercial applications, and to alter it and redistribute it 15 | // freely, subject to the following restrictions: 16 | // 17 | // 1. The origin of this software must not be misrepresented; you must not 18 | // claim that you wrote the original software. If you use this software 19 | // in a product, an acknowledgment in the product documentation would 20 | // be appreciated but is not required. 21 | // 22 | // 2. Altered source versions must be plainly marked as such, and must not 23 | // be misrepresented as being the original software. 24 | // 25 | // 3. This notice may not be removed or altered from any source 26 | // distribution. 27 | // 28 | //======================================================================== 29 | 30 | #ifndef _cocoa_platform_h_ 31 | #define _cocoa_platform_h_ 32 | 33 | 34 | #include 35 | 36 | #if defined(__OBJC__) 37 | #import 38 | #else 39 | #include 40 | typedef void* id; 41 | #endif 42 | 43 | #if defined(_GLFW_NSGL) 44 | #include "nsgl_platform.h" 45 | #else 46 | #error "No supported context creation API selected" 47 | #endif 48 | 49 | #include 50 | #include 51 | #include 52 | #include 53 | 54 | #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowNS ns 55 | #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryNS ns 56 | #define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorNS ns 57 | 58 | 59 | //======================================================================== 60 | // GLFW platform specific types 61 | //======================================================================== 62 | 63 | 64 | //------------------------------------------------------------------------ 65 | // Platform-specific window structure 66 | //------------------------------------------------------------------------ 67 | typedef struct _GLFWwindowNS 68 | { 69 | id object; 70 | id delegate; 71 | id view; 72 | unsigned int modifierFlags; 73 | } _GLFWwindowNS; 74 | 75 | 76 | //------------------------------------------------------------------------ 77 | // Joystick information & state 78 | //------------------------------------------------------------------------ 79 | typedef struct 80 | { 81 | int present; 82 | char name[256]; 83 | 84 | IOHIDDeviceInterface** interface; 85 | 86 | CFMutableArrayRef axisElements; 87 | CFMutableArrayRef buttonElements; 88 | CFMutableArrayRef hatElements; 89 | 90 | float* axes; 91 | unsigned char* buttons; 92 | 93 | } _GLFWjoy; 94 | 95 | 96 | //------------------------------------------------------------------------ 97 | // Platform-specific library global data for Cocoa 98 | //------------------------------------------------------------------------ 99 | typedef struct _GLFWlibraryNS 100 | { 101 | struct { 102 | double base; 103 | double resolution; 104 | } timer; 105 | 106 | CGEventSourceRef eventSource; 107 | id delegate; 108 | id autoreleasePool; 109 | id cursor; 110 | 111 | GLboolean cursorHidden; 112 | 113 | char* clipboardString; 114 | 115 | _GLFWjoy joysticks[GLFW_JOYSTICK_LAST + 1]; 116 | } _GLFWlibraryNS; 117 | 118 | 119 | //------------------------------------------------------------------------ 120 | // Platform-specific monitor structure 121 | //------------------------------------------------------------------------ 122 | typedef struct _GLFWmonitorNS 123 | { 124 | CGDirectDisplayID displayID; 125 | CGDisplayModeRef previousMode; 126 | id screen; 127 | 128 | } _GLFWmonitorNS; 129 | 130 | 131 | //======================================================================== 132 | // Prototypes for platform specific internal functions 133 | //======================================================================== 134 | 135 | // Time 136 | void _glfwInitTimer(void); 137 | 138 | // Joystick input 139 | void _glfwInitJoysticks(void); 140 | void _glfwTerminateJoysticks(void); 141 | 142 | // Fullscreen 143 | GLboolean _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired); 144 | void _glfwRestoreVideoMode(_GLFWmonitor* monitor); 145 | 146 | // OpenGL support 147 | int _glfwInitContextAPI(void); 148 | void _glfwTerminateContextAPI(void); 149 | int _glfwCreateContext(_GLFWwindow* window, 150 | const _GLFWwndconfig* wndconfig, 151 | const _GLFWfbconfig* fbconfig); 152 | void _glfwDestroyContext(_GLFWwindow* window); 153 | 154 | #endif // _cocoa_platform_h_ 155 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/src/x11_gamma.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW - An OpenGL library 3 | // Platform: X11 4 | // API version: 3.0 5 | // WWW: http://www.glfw.org/ 6 | //------------------------------------------------------------------------ 7 | // Copyright (c) 2010 Camilla Berglund 8 | // 9 | // This software is provided 'as-is', without any express or implied 10 | // warranty. In no event will the authors be held liable for any damages 11 | // arising from the use of this software. 12 | // 13 | // Permission is granted to anyone to use this software for any purpose, 14 | // including commercial applications, and to alter it and redistribute it 15 | // freely, subject to the following restrictions: 16 | // 17 | // 1. The origin of this software must not be misrepresented; you must not 18 | // claim that you wrote the original software. If you use this software 19 | // in a product, an acknowledgment in the product documentation would 20 | // be appreciated but is not required. 21 | // 22 | // 2. Altered source versions must be plainly marked as such, and must not 23 | // be misrepresented as being the original software. 24 | // 25 | // 3. This notice may not be removed or altered from any source 26 | // distribution. 27 | // 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #include 33 | #include 34 | 35 | 36 | ////////////////////////////////////////////////////////////////////////// 37 | ////// GLFW internal API ////// 38 | ////////////////////////////////////////////////////////////////////////// 39 | 40 | // Detect gamma ramp support 41 | // 42 | void _glfwInitGammaRamp(void) 43 | { 44 | // RandR gamma support is only available with version 1.2 and above 45 | if (_glfw.x11.randr.available && 46 | (_glfw.x11.randr.versionMajor > 1 || 47 | (_glfw.x11.randr.versionMajor == 1 && 48 | _glfw.x11.randr.versionMinor >= 2))) 49 | { 50 | // FIXME: Assumes that all monitors have the same size gamma tables 51 | // This is reasonable as I suspect the that if they did differ, it 52 | // would imply that setting the gamma size to an arbitary size is 53 | // possible as well. 54 | XRRScreenResources* rr = XRRGetScreenResources(_glfw.x11.display, 55 | _glfw.x11.root); 56 | 57 | if (XRRGetCrtcGammaSize(_glfw.x11.display, rr->crtcs[0]) == 0) 58 | { 59 | // This is probably older Nvidia RandR with broken gamma support 60 | // Flag it as useless and try Xf86VidMode below, if available 61 | _glfw.x11.randr.gammaBroken = GL_TRUE; 62 | } 63 | 64 | XRRFreeScreenResources(rr); 65 | } 66 | } 67 | 68 | 69 | ////////////////////////////////////////////////////////////////////////// 70 | ////// GLFW platform API ////// 71 | ////////////////////////////////////////////////////////////////////////// 72 | 73 | void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp) 74 | { 75 | if (_glfw.x11.randr.available && !_glfw.x11.randr.gammaBroken) 76 | { 77 | const size_t size = XRRGetCrtcGammaSize(_glfw.x11.display, 78 | monitor->x11.crtc); 79 | XRRCrtcGamma* gamma = XRRGetCrtcGamma(_glfw.x11.display, 80 | monitor->x11.crtc); 81 | 82 | _glfwAllocGammaRamp(ramp, size); 83 | 84 | memcpy(ramp->red, gamma->red, size * sizeof(unsigned short)); 85 | memcpy(ramp->green, gamma->green, size * sizeof(unsigned short)); 86 | memcpy(ramp->blue, gamma->blue, size * sizeof(unsigned short)); 87 | 88 | XRRFreeGamma(gamma); 89 | } 90 | else if (_glfw.x11.vidmode.available) 91 | { 92 | int size; 93 | XF86VidModeGetGammaRampSize(_glfw.x11.display, _glfw.x11.screen, &size); 94 | 95 | _glfwAllocGammaRamp(ramp, size); 96 | 97 | XF86VidModeGetGammaRamp(_glfw.x11.display, 98 | _glfw.x11.screen, 99 | ramp->size, ramp->red, ramp->green, ramp->blue); 100 | } 101 | } 102 | 103 | void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp) 104 | { 105 | if (_glfw.x11.randr.available && !_glfw.x11.randr.gammaBroken) 106 | { 107 | XRRCrtcGamma* gamma = XRRAllocGamma(ramp->size); 108 | 109 | memcpy(gamma->red, ramp->red, ramp->size * sizeof(unsigned short)); 110 | memcpy(gamma->green, ramp->green, ramp->size * sizeof(unsigned short)); 111 | memcpy(gamma->blue, ramp->blue, ramp->size * sizeof(unsigned short)); 112 | 113 | XRRSetCrtcGamma(_glfw.x11.display, monitor->x11.crtc, gamma); 114 | XRRFreeGamma(gamma); 115 | } 116 | else if (_glfw.x11.vidmode.available) 117 | { 118 | XF86VidModeSetGammaRamp(_glfw.x11.display, 119 | _glfw.x11.screen, 120 | ramp->size, 121 | (unsigned short*) ramp->red, 122 | (unsigned short*) ramp->green, 123 | (unsigned short*) ramp->blue); 124 | } 125 | } 126 | 127 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/src/glx_platform.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW - An OpenGL library 3 | // Platform: X11/GLX 4 | // API version: 3.0 5 | // WWW: http://www.glfw.org/ 6 | //------------------------------------------------------------------------ 7 | // Copyright (c) 2002-2006 Marcus Geelnard 8 | // Copyright (c) 2006-2010 Camilla Berglund 9 | // 10 | // This software is provided 'as-is', without any express or implied 11 | // warranty. In no event will the authors be held liable for any damages 12 | // arising from the use of this software. 13 | // 14 | // Permission is granted to anyone to use this software for any purpose, 15 | // including commercial applications, and to alter it and redistribute it 16 | // freely, subject to the following restrictions: 17 | // 18 | // 1. The origin of this software must not be misrepresented; you must not 19 | // claim that you wrote the original software. If you use this software 20 | // in a product, an acknowledgment in the product documentation would 21 | // be appreciated but is not required. 22 | // 23 | // 2. Altered source versions must be plainly marked as such, and must not 24 | // be misrepresented as being the original software. 25 | // 26 | // 3. This notice may not be removed or altered from any source 27 | // distribution. 28 | // 29 | //======================================================================== 30 | 31 | #ifndef _glx_platform_h_ 32 | #define _glx_platform_h_ 33 | 34 | #define GLX_GLXEXT_LEGACY 35 | #include 36 | 37 | // This path may need to be changed if you build GLFW using your own setup 38 | // We ship and use our own copy of glxext.h since GLFW uses fairly new 39 | // extensions and not all operating systems come with an up-to-date version 40 | #include "../deps/GL/glxext.h" 41 | 42 | // Do we have support for dlopen/dlsym? 43 | #if defined(_GLFW_HAS_DLOPEN) 44 | #include 45 | #endif 46 | 47 | // We support four different ways for getting addresses for GL/GLX 48 | // extension functions: glXGetProcAddress, glXGetProcAddressARB, 49 | // glXGetProcAddressEXT, and dlsym 50 | #if defined(_GLFW_HAS_GLXGETPROCADDRESSARB) 51 | #define _glfw_glXGetProcAddress(x) glXGetProcAddressARB(x) 52 | #elif defined(_GLFW_HAS_GLXGETPROCADDRESS) 53 | #define _glfw_glXGetProcAddress(x) glXGetProcAddress(x) 54 | #elif defined(_GLFW_HAS_GLXGETPROCADDRESSEXT) 55 | #define _glfw_glXGetProcAddress(x) glXGetProcAddressEXT(x) 56 | #elif defined(_GLFW_HAS_DLOPEN) 57 | #define _glfw_glXGetProcAddress(x) dlsym(_glfw.glx.libGL, x) 58 | #define _GLFW_DLOPEN_LIBGL 59 | #else 60 | #error "No OpenGL entry point retrieval mechanism was enabled" 61 | #endif 62 | 63 | #define _GLFW_PLATFORM_FBCONFIG GLXFBConfig glx 64 | #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextGLX glx 65 | #define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryGLX glx 66 | 67 | #ifndef GLX_MESA_swap_control 68 | typedef int (*PFNGLXSWAPINTERVALMESAPROC)(int); 69 | #endif 70 | 71 | 72 | //======================================================================== 73 | // GLFW platform specific types 74 | //======================================================================== 75 | 76 | //------------------------------------------------------------------------ 77 | // Platform-specific OpenGL context structure 78 | //------------------------------------------------------------------------ 79 | typedef struct _GLFWcontextGLX 80 | { 81 | GLXContext context; // OpenGL rendering context 82 | XVisualInfo* visual; // Visual for selected GLXFBConfig 83 | 84 | } _GLFWcontextGLX; 85 | 86 | 87 | //------------------------------------------------------------------------ 88 | // Platform-specific library global data for GLX 89 | //------------------------------------------------------------------------ 90 | typedef struct _GLFWlibraryGLX 91 | { 92 | // Server-side GLX version 93 | int versionMajor, versionMinor; 94 | int eventBase; 95 | int errorBase; 96 | 97 | // TLS key for per-thread current context/window 98 | pthread_key_t current; 99 | 100 | // GLX error code received by Xlib error callback 101 | int errorCode; 102 | 103 | // GLX extensions 104 | PFNGLXSWAPINTERVALSGIPROC SwapIntervalSGI; 105 | PFNGLXSWAPINTERVALEXTPROC SwapIntervalEXT; 106 | PFNGLXSWAPINTERVALMESAPROC SwapIntervalMESA; 107 | PFNGLXGETFBCONFIGATTRIBSGIXPROC GetFBConfigAttribSGIX; 108 | PFNGLXCHOOSEFBCONFIGSGIXPROC ChooseFBConfigSGIX; 109 | PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC CreateContextWithConfigSGIX; 110 | PFNGLXGETVISUALFROMFBCONFIGSGIXPROC GetVisualFromFBConfigSGIX; 111 | PFNGLXCREATECONTEXTATTRIBSARBPROC CreateContextAttribsARB; 112 | GLboolean SGIX_fbconfig; 113 | GLboolean SGI_swap_control; 114 | GLboolean EXT_swap_control; 115 | GLboolean MESA_swap_control; 116 | GLboolean ARB_multisample; 117 | GLboolean ARB_framebuffer_sRGB; 118 | GLboolean ARB_create_context; 119 | GLboolean ARB_create_context_profile; 120 | GLboolean ARB_create_context_robustness; 121 | GLboolean EXT_create_context_es2_profile; 122 | 123 | #if defined(_GLFW_DLOPEN_LIBGL) 124 | void* libGL; // dlopen handle for libGL.so 125 | #endif 126 | } _GLFWlibraryGLX; 127 | 128 | 129 | #endif // _glx_platform_h_ 130 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/src/win32_joystick.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW - An OpenGL library 3 | // Platform: Win32 4 | // API version: 3.0 5 | // WWW: http://www.glfw.org/ 6 | //------------------------------------------------------------------------ 7 | // Copyright (c) 2002-2006 Marcus Geelnard 8 | // Copyright (c) 2006-2010 Camilla Berglund 9 | // 10 | // This software is provided 'as-is', without any express or implied 11 | // warranty. In no event will the authors be held liable for any damages 12 | // arising from the use of this software. 13 | // 14 | // Permission is granted to anyone to use this software for any purpose, 15 | // including commercial applications, and to alter it and redistribute it 16 | // freely, subject to the following restrictions: 17 | // 18 | // 1. The origin of this software must not be misrepresented; you must not 19 | // claim that you wrote the original software. If you use this software 20 | // in a product, an acknowledgment in the product documentation would 21 | // be appreciated but is not required. 22 | // 23 | // 2. Altered source versions must be plainly marked as such, and must not 24 | // be misrepresented as being the original software. 25 | // 26 | // 3. This notice may not be removed or altered from any source 27 | // distribution. 28 | // 29 | //======================================================================== 30 | 31 | #include "internal.h" 32 | 33 | #include 34 | 35 | 36 | ////////////////////////////////////////////////////////////////////////// 37 | ////// GLFW internal API ////// 38 | ////////////////////////////////////////////////////////////////////////// 39 | 40 | // Calculate normalized joystick position 41 | // 42 | static float calcJoystickPos(DWORD pos, DWORD min, DWORD max) 43 | { 44 | float fpos = (float) pos; 45 | float fmin = (float) min; 46 | float fmax = (float) max; 47 | 48 | return (2.f * (fpos - fmin) / (fmax - fmin)) - 1.f; 49 | } 50 | 51 | 52 | ////////////////////////////////////////////////////////////////////////// 53 | ////// GLFW internal API ////// 54 | ////////////////////////////////////////////////////////////////////////// 55 | 56 | // Initialize joystick interface 57 | // 58 | void _glfwInitJoysticks(void) 59 | { 60 | } 61 | 62 | // Close all opened joystick handles 63 | // 64 | void _glfwTerminateJoysticks(void) 65 | { 66 | int i; 67 | 68 | for (i = 0; i < GLFW_JOYSTICK_LAST; i++) 69 | free(_glfw.win32.joystick[i].name); 70 | } 71 | 72 | 73 | ////////////////////////////////////////////////////////////////////////// 74 | ////// GLFW platform API ////// 75 | ////////////////////////////////////////////////////////////////////////// 76 | 77 | int _glfwPlatformJoystickPresent(int joy) 78 | { 79 | JOYINFO ji; 80 | 81 | if (_glfw_joyGetPos(joy, &ji) != JOYERR_NOERROR) 82 | return GL_FALSE; 83 | 84 | return GL_TRUE; 85 | } 86 | 87 | const float* _glfwPlatformGetJoystickAxes(int joy, int* count) 88 | { 89 | JOYCAPS jc; 90 | JOYINFOEX ji; 91 | float* axes = _glfw.win32.joystick[joy].axes; 92 | 93 | if (_glfw_joyGetDevCaps(joy, &jc, sizeof(JOYCAPS)) != JOYERR_NOERROR) 94 | return NULL; 95 | 96 | ji.dwSize = sizeof(JOYINFOEX); 97 | ji.dwFlags = JOY_RETURNX | JOY_RETURNY | JOY_RETURNZ | 98 | JOY_RETURNR | JOY_RETURNU | JOY_RETURNV; 99 | if (_glfw_joyGetPosEx(joy, &ji) != JOYERR_NOERROR) 100 | return NULL; 101 | 102 | axes[(*count)++] = calcJoystickPos(ji.dwXpos, jc.wXmin, jc.wXmax); 103 | axes[(*count)++] = -calcJoystickPos(ji.dwYpos, jc.wYmin, jc.wYmax); 104 | 105 | if (jc.wCaps & JOYCAPS_HASZ) 106 | axes[(*count)++] = calcJoystickPos(ji.dwZpos, jc.wZmin, jc.wZmax); 107 | 108 | if (jc.wCaps & JOYCAPS_HASR) 109 | axes[(*count)++] = calcJoystickPos(ji.dwRpos, jc.wRmin, jc.wRmax); 110 | 111 | if (jc.wCaps & JOYCAPS_HASU) 112 | axes[(*count)++] = calcJoystickPos(ji.dwUpos, jc.wUmin, jc.wUmax); 113 | 114 | if (jc.wCaps & JOYCAPS_HASV) 115 | axes[(*count)++] = -calcJoystickPos(ji.dwVpos, jc.wVmin, jc.wVmax); 116 | 117 | return axes; 118 | } 119 | 120 | const unsigned char* _glfwPlatformGetJoystickButtons(int joy, int* count) 121 | { 122 | JOYCAPS jc; 123 | JOYINFOEX ji; 124 | unsigned char* buttons = _glfw.win32.joystick[joy].buttons; 125 | 126 | if (_glfw_joyGetDevCaps(joy, &jc, sizeof(JOYCAPS)) != JOYERR_NOERROR) 127 | return NULL; 128 | 129 | ji.dwSize = sizeof(JOYINFOEX); 130 | ji.dwFlags = JOY_RETURNBUTTONS | JOY_RETURNPOV; 131 | if (_glfw_joyGetPosEx(joy, &ji) != JOYERR_NOERROR) 132 | return NULL; 133 | 134 | while (*count < (int) jc.wNumButtons) 135 | { 136 | buttons[*count] = (unsigned char) 137 | (ji.dwButtons & (1UL << *count) ? GLFW_PRESS : GLFW_RELEASE); 138 | (*count)++; 139 | } 140 | 141 | // Virtual buttons - Inject data from hats 142 | // Each hat is exposed as 4 buttons which exposes 8 directions with 143 | // concurrent button presses 144 | // NOTE: this API exposes only one hat 145 | 146 | if ((jc.wCaps & JOYCAPS_HASPOV) && (jc.wCaps & JOYCAPS_POV4DIR)) 147 | { 148 | int i, value = ji.dwPOV / 100 / 45; 149 | 150 | // Bit fields of button presses for each direction, including nil 151 | const int directions[9] = { 1, 3, 2, 6, 4, 12, 8, 9, 0 }; 152 | 153 | if (value < 0 || value > 8) 154 | value = 8; 155 | 156 | for (i = 0; i < 4; i++) 157 | { 158 | if (directions[value] & (1 << i)) 159 | buttons[(*count)++] = GLFW_PRESS; 160 | else 161 | buttons[(*count)++] = GLFW_RELEASE; 162 | } 163 | } 164 | 165 | return buttons; 166 | } 167 | 168 | const char* _glfwPlatformGetJoystickName(int joy) 169 | { 170 | JOYCAPS jc; 171 | 172 | if (_glfw_joyGetDevCaps(joy, &jc, sizeof(JOYCAPS)) != JOYERR_NOERROR) 173 | return NULL; 174 | 175 | free(_glfw.win32.joystick[joy].name); 176 | _glfw.win32.joystick[joy].name = _glfwCreateUTF8FromWideString(jc.szPname); 177 | 178 | return _glfw.win32.joystick[joy].name; 179 | } 180 | 181 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/include/GLFW/glfw3native.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * GLFW - An OpenGL library 3 | * API version: 3.0 4 | * WWW: http://www.glfw.org/ 5 | *------------------------------------------------------------------------ 6 | * Copyright (c) 2002-2006 Marcus Geelnard 7 | * Copyright (c) 2006-2010 Camilla Berglund 8 | * 9 | * This software is provided 'as-is', without any express or implied 10 | * warranty. In no event will the authors be held liable for any damages 11 | * arising from the use of this software. 12 | * 13 | * Permission is granted to anyone to use this software for any purpose, 14 | * including commercial applications, and to alter it and redistribute it 15 | * freely, subject to the following restrictions: 16 | * 17 | * 1. The origin of this software must not be misrepresented; you must not 18 | * claim that you wrote the original software. If you use this software 19 | * in a product, an acknowledgment in the product documentation would 20 | * be appreciated but is not required. 21 | * 22 | * 2. Altered source versions must be plainly marked as such, and must not 23 | * be misrepresented as being the original software. 24 | * 25 | * 3. This notice may not be removed or altered from any source 26 | * distribution. 27 | * 28 | *************************************************************************/ 29 | 30 | #ifndef _glfw3_native_h_ 31 | #define _glfw3_native_h_ 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | 38 | /************************************************************************* 39 | * Doxygen documentation 40 | *************************************************************************/ 41 | 42 | /*! @defgroup native Native access 43 | * 44 | * **By using the native API, you assert that you know what you are doing and 45 | * how to fix problems caused by using it. If you don't, you shouldn't be 46 | * using it.** 47 | * 48 | * Before the inclusion of @ref glfw3native.h, you must define exactly one 49 | * window API macro and exactly one context API macro. Failure to do this 50 | * will cause a compile-time error. 51 | * 52 | * The available window API macros are: 53 | * * `GLFW_EXPOSE_NATIVE_WIN32` 54 | * * `GLFW_EXPOSE_NATIVE_COCOA` 55 | * * `GLFW_EXPOSE_NATIVE_X11` 56 | * 57 | * The available context API macros are: 58 | * * `GLFW_EXPOSE_NATIVE_WGL` 59 | * * `GLFW_EXPOSE_NATIVE_NSGL` 60 | * * `GLFW_EXPOSE_NATIVE_GLX` 61 | * * `GLFW_EXPOSE_NATIVE_EGL` 62 | * 63 | * These macros select which of the native access functions that are declared 64 | * and which platform-specific headers to include. It is then up your (by 65 | * definition platform-specific) code to handle which of these should be 66 | * defined. 67 | */ 68 | 69 | 70 | /************************************************************************* 71 | * System headers and types 72 | *************************************************************************/ 73 | 74 | #if defined(GLFW_EXPOSE_NATIVE_WIN32) 75 | #include 76 | #elif defined(GLFW_EXPOSE_NATIVE_COCOA) 77 | #if defined(__OBJC__) 78 | #import 79 | #else 80 | typedef void* id; 81 | #endif 82 | #elif defined(GLFW_EXPOSE_NATIVE_X11) 83 | #include 84 | #else 85 | #error "No window API specified" 86 | #endif 87 | 88 | #if defined(GLFW_EXPOSE_NATIVE_WGL) 89 | /* WGL is declared by windows.h */ 90 | #elif defined(GLFW_EXPOSE_NATIVE_NSGL) 91 | /* NSGL is declared by Cocoa.h */ 92 | #elif defined(GLFW_EXPOSE_NATIVE_GLX) 93 | #include 94 | #elif defined(GLFW_EXPOSE_NATIVE_EGL) 95 | #include 96 | #else 97 | #error "No context API specified" 98 | #endif 99 | 100 | 101 | /************************************************************************* 102 | * Functions 103 | *************************************************************************/ 104 | 105 | #if defined(GLFW_EXPOSE_NATIVE_WIN32) 106 | /*! @brief Returns the `HWND` of the specified window. 107 | * @return The `HWND` of the specified window. 108 | * @ingroup native 109 | */ 110 | GLFWAPI HWND glfwGetWin32Window(GLFWwindow* window); 111 | #endif 112 | 113 | #if defined(GLFW_EXPOSE_NATIVE_WGL) 114 | /*! @brief Returns the `HGLRC` of the specified window. 115 | * @return The `HGLRC` of the specified window. 116 | * @ingroup native 117 | */ 118 | GLFWAPI HGLRC glfwGetWGLContext(GLFWwindow* window); 119 | #endif 120 | 121 | #if defined(GLFW_EXPOSE_NATIVE_COCOA) 122 | /*! @brief Returns the `NSWindow` of the specified window. 123 | * @return The `NSWindow` of the specified window. 124 | * @ingroup native 125 | */ 126 | GLFWAPI id glfwGetCocoaWindow(GLFWwindow* window); 127 | #endif 128 | 129 | #if defined(GLFW_EXPOSE_NATIVE_NSGL) 130 | /*! @brief Returns the `NSOpenGLContext` of the specified window. 131 | * @return The `NSOpenGLContext` of the specified window. 132 | * @ingroup native 133 | */ 134 | GLFWAPI id glfwGetNSGLContext(GLFWwindow* window); 135 | #endif 136 | 137 | #if defined(GLFW_EXPOSE_NATIVE_X11) 138 | /*! @brief Returns the `Display` used by GLFW. 139 | * @return The `Display` used by GLFW. 140 | * @ingroup native 141 | */ 142 | GLFWAPI Display* glfwGetX11Display(void); 143 | /*! @brief Returns the `Window` of the specified window. 144 | * @return The `Window` of the specified window. 145 | * @ingroup native 146 | */ 147 | GLFWAPI Window glfwGetX11Window(GLFWwindow* window); 148 | #endif 149 | 150 | #if defined(GLFW_EXPOSE_NATIVE_GLX) 151 | /*! @brief Returns the `GLXContext` of the specified window. 152 | * @return The `GLXContext` of the specified window. 153 | * @ingroup native 154 | */ 155 | GLFWAPI GLXContext glfwGetGLXContext(GLFWwindow* window); 156 | #endif 157 | 158 | #if defined(GLFW_EXPOSE_NATIVE_EGL) 159 | /*! @brief Returns the `EGLDisplay` used by GLFW. 160 | * @return The `EGLDisplay` used by GLFW. 161 | * @ingroup native 162 | */ 163 | GLFWAPI EGLDisplay glfwGetEGLDisplay(void); 164 | /*! @brief Returns the `EGLContext` of the specified window. 165 | * @return The `EGLContext` of the specified window. 166 | * @ingroup native 167 | */ 168 | GLFWAPI EGLContext glfwGetEGLContext(GLFWwindow* window); 169 | /*! @brief Returns the `EGLSurface` of the specified window. 170 | * @return The `EGLSurface` of the specified window. 171 | * @ingroup native 172 | */ 173 | GLFWAPI EGLSurface glfwGetEGLSurface(GLFWwindow* window); 174 | #endif 175 | 176 | #ifdef __cplusplus 177 | } 178 | #endif 179 | 180 | #endif /* _glfw3_native_h_ */ 181 | 182 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/src/init.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW - An OpenGL library 3 | // Platform: Any 4 | // API version: 3.0 5 | // WWW: http://www.glfw.org/ 6 | //------------------------------------------------------------------------ 7 | // Copyright (c) 2002-2006 Marcus Geelnard 8 | // Copyright (c) 2006-2010 Camilla Berglund 9 | // 10 | // This software is provided 'as-is', without any express or implied 11 | // warranty. In no event will the authors be held liable for any damages 12 | // arising from the use of this software. 13 | // 14 | // Permission is granted to anyone to use this software for any purpose, 15 | // including commercial applications, and to alter it and redistribute it 16 | // freely, subject to the following restrictions: 17 | // 18 | // 1. The origin of this software must not be misrepresented; you must not 19 | // claim that you wrote the original software. If you use this software 20 | // in a product, an acknowledgment in the product documentation would 21 | // be appreciated but is not required. 22 | // 23 | // 2. Altered source versions must be plainly marked as such, and must not 24 | // be misrepresented as being the original software. 25 | // 26 | // 3. This notice may not be removed or altered from any source 27 | // distribution. 28 | // 29 | //======================================================================== 30 | 31 | #include "internal.h" 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | 39 | // Global state shared between compilation units of GLFW 40 | // These are documented in internal.h 41 | // 42 | GLboolean _glfwInitialized = GL_FALSE; 43 | _GLFWlibrary _glfw; 44 | 45 | 46 | // The current error callback 47 | // This is outside of _glfw so it can be initialized and usable before 48 | // glfwInit is called, which lets that function report errors 49 | // 50 | static GLFWerrorfun _glfwErrorCallback = NULL; 51 | 52 | 53 | // Returns a generic string representation of the specified error 54 | // 55 | static const char* getErrorString(int error) 56 | { 57 | switch (error) 58 | { 59 | case GLFW_NOT_INITIALIZED: 60 | return "The GLFW library is not initialized"; 61 | case GLFW_NO_CURRENT_CONTEXT: 62 | return "There is no current context"; 63 | case GLFW_INVALID_ENUM: 64 | return "Invalid argument for enum parameter"; 65 | case GLFW_INVALID_VALUE: 66 | return "Invalid value for parameter"; 67 | case GLFW_OUT_OF_MEMORY: 68 | return "Out of memory"; 69 | case GLFW_API_UNAVAILABLE: 70 | return "The requested client API is unavailable"; 71 | case GLFW_VERSION_UNAVAILABLE: 72 | return "The requested client API version is unavailable"; 73 | case GLFW_PLATFORM_ERROR: 74 | return "A platform-specific error occurred"; 75 | case GLFW_FORMAT_UNAVAILABLE: 76 | return "The requested format is unavailable"; 77 | } 78 | 79 | return "ERROR: UNKNOWN ERROR TOKEN PASSED TO glfwErrorString"; 80 | } 81 | 82 | 83 | ////////////////////////////////////////////////////////////////////////// 84 | ////// GLFW event API ////// 85 | ////////////////////////////////////////////////////////////////////////// 86 | 87 | void _glfwInputError(int error, const char* format, ...) 88 | { 89 | if (_glfwErrorCallback) 90 | { 91 | char buffer[16384]; 92 | const char* description; 93 | 94 | if (format) 95 | { 96 | int count; 97 | va_list vl; 98 | 99 | va_start(vl, format); 100 | count = vsnprintf(buffer, sizeof(buffer), format, vl); 101 | va_end(vl); 102 | 103 | if (count < 0) 104 | buffer[sizeof(buffer) - 1] = '\0'; 105 | 106 | description = buffer; 107 | } 108 | else 109 | description = getErrorString(error); 110 | 111 | _glfwErrorCallback(error, description); 112 | } 113 | } 114 | 115 | 116 | ////////////////////////////////////////////////////////////////////////// 117 | ////// GLFW public API ////// 118 | ////////////////////////////////////////////////////////////////////////// 119 | 120 | GLFWAPI int glfwInit(void) 121 | { 122 | if (_glfwInitialized) 123 | return GL_TRUE; 124 | 125 | memset(&_glfw, 0, sizeof(_glfw)); 126 | 127 | if (!_glfwPlatformInit()) 128 | { 129 | _glfwPlatformTerminate(); 130 | return GL_FALSE; 131 | } 132 | 133 | _glfw.monitors = _glfwPlatformGetMonitors(&_glfw.monitorCount); 134 | if (_glfw.monitors == NULL) 135 | { 136 | _glfwErrorCallback(GLFW_PLATFORM_ERROR, "No monitors found"); 137 | _glfwPlatformTerminate(); 138 | return GL_FALSE; 139 | } 140 | 141 | _glfwInitialized = GL_TRUE; 142 | 143 | // Not all window hints have zero as their default value 144 | glfwDefaultWindowHints(); 145 | 146 | return GL_TRUE; 147 | } 148 | 149 | GLFWAPI void glfwTerminate(void) 150 | { 151 | int i; 152 | 153 | if (!_glfwInitialized) 154 | return; 155 | 156 | // Close all remaining windows 157 | while (_glfw.windowListHead) 158 | glfwDestroyWindow((GLFWwindow*) _glfw.windowListHead); 159 | 160 | for (i = 0; i < _glfw.monitorCount; i++) 161 | { 162 | _GLFWmonitor* monitor = _glfw.monitors[i]; 163 | if (monitor->originalRamp.size) 164 | _glfwPlatformSetGammaRamp(monitor, &monitor->originalRamp); 165 | } 166 | 167 | _glfwDestroyMonitors(_glfw.monitors, _glfw.monitorCount); 168 | _glfw.monitors = NULL; 169 | _glfw.monitorCount = 0; 170 | 171 | _glfwPlatformTerminate(); 172 | 173 | _glfwInitialized = GL_FALSE; 174 | } 175 | 176 | GLFWAPI void glfwGetVersion(int* major, int* minor, int* rev) 177 | { 178 | if (major != NULL) 179 | *major = GLFW_VERSION_MAJOR; 180 | 181 | if (minor != NULL) 182 | *minor = GLFW_VERSION_MINOR; 183 | 184 | if (rev != NULL) 185 | *rev = GLFW_VERSION_REVISION; 186 | } 187 | 188 | GLFWAPI const char* glfwGetVersionString(void) 189 | { 190 | return _glfwPlatformGetVersionString(); 191 | } 192 | 193 | GLFWAPI GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cbfun) 194 | { 195 | GLFWerrorfun previous = _glfwErrorCallback; 196 | _glfwErrorCallback = cbfun; 197 | return previous; 198 | } 199 | 200 | -------------------------------------------------------------------------------- /tests/raytracing/main.c: -------------------------------------------------------------------------------- 1 | /*====================================================================== 2 | Maratis Tiny C Library 3 | version 1.0 4 | ------------------------------------------------------------------------ 5 | Copyright (c) 2015 Anael Seghezzi 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 | /* raytracing test */ 29 | 30 | #define M_MATH_IMPLEMENTATION 31 | #define M_IMAGE_IMPLEMENTATION 32 | #include 33 | #include 34 | 35 | #include "../test.h" 36 | 37 | #define USE_NOISE /* comment to disable 3d noise (simple sphere raytracing) */ 38 | 39 | static struct m_image test_buffer = M_IMAGE_IDENTITY(); 40 | 41 | /* approximative noise */ 42 | static struct m_image rand_image = M_IMAGE_IDENTITY(); 43 | static struct m_image tmp = M_IMAGE_IDENTITY(); 44 | 45 | void init_noise(void) 46 | { 47 | int i; 48 | m_image_create(&rand_image, M_FLOAT, 16, 16, 2); 49 | for (i = 0; i < rand_image.size; i++) 50 | ((float *)rand_image.data)[i] = (float)rand() / (float)RAND_MAX; 51 | } 52 | 53 | void destroy_noise(void) 54 | { 55 | m_image_destroy(&rand_image); 56 | } 57 | 58 | float fast_noise(float x, float y, float z) 59 | { 60 | float values[2]; 61 | float i = z - floorf(z); 62 | m_image_sub_pixel(&rand_image, x + z + 8, y + z + 8, values); 63 | return values[0] * (1.0f - i) + values[1] * i; 64 | } 65 | 66 | #define GET_RAY(ray, px, py, pz, hw, hh, ratio)\ 67 | {\ 68 | float3 pt = {((float)px - hw) / hw, (-((float)py - hh) / hh) * ratio, pz};\ 69 | float ptl = 1.0f / M_LENGHT3(pt);\ 70 | ray.x = pt.x * ptl;\ 71 | ray.y = pt.y * ptl;\ 72 | ray.z = pt.z * ptl;\ 73 | } 74 | 75 | static void draw(void) 76 | { 77 | float *data = (float *)test_buffer.data; 78 | int w = test_buffer.width; 79 | int h = test_buffer.height; 80 | int y; 81 | 82 | float3 sphere_pos; 83 | float3 light_dir; 84 | float z_near = 1e-4; 85 | float ambient = 0.15f; 86 | float sphere_radius2; 87 | float sphere_tex_unit; 88 | float hw = w * 0.5f; 89 | float hh = h * 0.5f; 90 | float ratio = (float)test_height / (float)test_width; 91 | 92 | /* light */ 93 | light_dir.x = 0.5f; 94 | light_dir.y = 0.25f; 95 | light_dir.z = -0.5f; 96 | 97 | /* sphere */ 98 | sphere_radius2 = 150; 99 | sphere_pos.x = cosf(test_t * 0.025f) * 20.0f; 100 | sphere_pos.y = 0.0f; 101 | sphere_pos.z = 50.0f + (sinf(test_t * 0.025f) + 1.0f) * 70.0f; 102 | sphere_tex_unit = 0.25f; 103 | 104 | /* clear */ 105 | memset(test_buffer.data, 0, test_buffer.size * sizeof(float)); 106 | 107 | /* raytrace */ 108 | #pragma omp parallel for schedule(dynamic, 8) 109 | for (y = 0; y < h; y++) { 110 | 111 | float *pixel = data + y * w * 3; 112 | int x; 113 | 114 | for (x = 0; x < w; x++) { 115 | 116 | float3 origin = {0, 0, 0}; 117 | float3 ray, march_dir; 118 | float march_step; 119 | float idist, dist = 0, Z = 1e20; 120 | 121 | /* get ray from pixel position */ 122 | GET_RAY(ray, x, y, 1.35f, hw, hh, ratio); 123 | 124 | march_step = 0.25f; 125 | march_dir.x = ray.x * march_step; 126 | march_dir.y = ray.y * march_step; 127 | march_dir.z = ray.z * march_step; 128 | 129 | /* sphere */ 130 | m_3d_ray_sphere_intersection_in_out(&origin, &ray, &sphere_pos, sphere_radius2, &dist, &idist); 131 | if (dist > z_near) { 132 | 133 | if (dist < Z) { 134 | 135 | float3 rd = {ray.x * dist, ray.y * dist, ray.z * dist}; 136 | float3 pos = {origin.x + rd.x, origin.y + rd.y, origin.z + rd.z}; 137 | 138 | /* simple sphere */ 139 | #ifndef USE_NOISE 140 | { 141 | float3 normal; 142 | float diffuse; 143 | M_SUB3(normal, pos, sphere_pos); 144 | M_NORMALIZE3(normal, normal); 145 | diffuse = M_DOT3(normal, light_dir); 146 | diffuse = M_MAX(0, diffuse); 147 | pixel[0] = ambient + diffuse; 148 | pixel[1] = ambient + diffuse; 149 | pixel[2] = ambient + diffuse; 150 | Z = dist; 151 | } 152 | /* volumetric ray marching inside a sphere (perlin noise test) */ 153 | #else 154 | { 155 | float3 march = pos; /* starting at sphere intersection */ 156 | int i; 157 | 158 | for (i = 0; i < 256; i++) { 159 | 160 | float3 vcoord = { 161 | (march.x - sphere_pos.x) * sphere_tex_unit, 162 | (march.y - sphere_pos.y) * sphere_tex_unit, 163 | (march.z - sphere_pos.z) * sphere_tex_unit 164 | }; 165 | 166 | float perlin = fast_noise(vcoord.x, vcoord.y, vcoord.z); 167 | if (perlin > 0.6f) { 168 | 169 | /* render */ 170 | float3 normal; 171 | float diffuse; 172 | 173 | if (i == 0) { 174 | /* sphere normal */ 175 | M_SUB3(normal, pos, sphere_pos); 176 | M_NORMALIZE3(normal, normal); 177 | } else { 178 | /* volume normal */ 179 | normal.x = perlin - fast_noise(vcoord.x + 0.0001f, vcoord.y, vcoord.z); 180 | normal.y = perlin - fast_noise(vcoord.x, vcoord.y + 0.0001f, vcoord.z); 181 | normal.z = perlin - fast_noise(vcoord.x, vcoord.y, vcoord.z + 0.0001f); 182 | M_NORMALIZE3(normal, normal); 183 | } 184 | 185 | diffuse = M_DOT3(normal, light_dir); 186 | diffuse = M_MAX(0, diffuse); 187 | pixel[0] = ambient + diffuse; 188 | pixel[1] = ambient + diffuse; 189 | pixel[2] = ambient + diffuse; 190 | Z = dist; 191 | break; 192 | } 193 | 194 | /* march */ 195 | M_ADD3(march, march, march_dir); 196 | dist += march_step; 197 | 198 | if (dist > idist) /* out of the sphere */ 199 | break; 200 | } 201 | } 202 | #endif 203 | } 204 | } 205 | 206 | pixel += 3; 207 | } 208 | } 209 | } 210 | 211 | void main_loop(void) 212 | { 213 | draw(); 214 | test_swap_buffer(&test_buffer); 215 | test_update(); 216 | } 217 | 218 | int main(int argc, char **argv) 219 | { 220 | if (! test_create("M - RaytracingTest", 256, 256)) 221 | return EXIT_FAILURE; 222 | 223 | m_image_create(&test_buffer, M_FLOAT, 256, 256, 3); 224 | init_noise(); 225 | 226 | #ifdef __EMSCRIPTEN__ 227 | emscripten_set_main_loop(main_loop, 0, 1); 228 | #else 229 | while (test_state) { 230 | main_loop(); 231 | thrd_yield(); 232 | } 233 | #endif 234 | 235 | m_image_destroy(&test_buffer); 236 | destroy_noise(); 237 | test_destroy(); 238 | return EXIT_SUCCESS; 239 | } 240 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/deps/getopt.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * getopt.c - competent and free getopt library. 3 | * $Header: /cvsroot/freegetopt/freegetopt/getopt.c,v 1.2 2003/10/26 03:10:20 vindaci Exp $ 4 | * 5 | * Copyright (c)2002-2003 Mark K. Kim 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 12 | * * Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 15 | * * Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in 17 | * the documentation and/or other materials provided with the 18 | * distribution. 19 | * 20 | * * Neither the original author of this software nor the names of its 21 | * contributors may be used to endorse or promote products derived 22 | * from this software without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 28 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 31 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 32 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 33 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 34 | * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 35 | * DAMAGE. 36 | */ 37 | #ifndef _CRT_SECURE_NO_WARNINGS 38 | #define _CRT_SECURE_NO_WARNINGS 39 | #endif 40 | 41 | #include 42 | #include 43 | #include 44 | #include "getopt.h" 45 | 46 | /* 2013-01-06 Camilla Berglund 47 | * 48 | * Only define _CRT_SECURE_NO_WARNINGS if not already defined. 49 | */ 50 | /* 2012-08-12 Lambert Clara 51 | * 52 | * Constify third argument of getopt. 53 | */ 54 | /* 2011-07-27 Camilla Berglund 55 | * 56 | * Added _CRT_SECURE_NO_WARNINGS macro. 57 | */ 58 | /* 2009-10-12 Camilla Berglund 59 | * 60 | * Removed unused global static variable 'ID'. 61 | */ 62 | 63 | char* optarg = NULL; 64 | int optind = 0; 65 | int opterr = 1; 66 | int optopt = '?'; 67 | 68 | 69 | static char** prev_argv = NULL; /* Keep a copy of argv and argc to */ 70 | static int prev_argc = 0; /* tell if getopt params change */ 71 | static int argv_index = 0; /* Option we're checking */ 72 | static int argv_index2 = 0; /* Option argument we're checking */ 73 | static int opt_offset = 0; /* Index into compounded "-option" */ 74 | static int dashdash = 0; /* True if "--" option reached */ 75 | static int nonopt = 0; /* How many nonopts we've found */ 76 | 77 | static void increment_index() 78 | { 79 | /* Move onto the next option */ 80 | if(argv_index < argv_index2) 81 | { 82 | while(prev_argv[++argv_index] && prev_argv[argv_index][0] != '-' 83 | && argv_index < argv_index2+1); 84 | } 85 | else argv_index++; 86 | opt_offset = 1; 87 | } 88 | 89 | 90 | /* 91 | * Permutes argv[] so that the argument currently being processed is moved 92 | * to the end. 93 | */ 94 | static int permute_argv_once() 95 | { 96 | /* Movability check */ 97 | if(argv_index + nonopt >= prev_argc) return 1; 98 | /* Move the current option to the end, bring the others to front */ 99 | else 100 | { 101 | char* tmp = prev_argv[argv_index]; 102 | 103 | /* Move the data */ 104 | memmove(&prev_argv[argv_index], &prev_argv[argv_index+1], 105 | sizeof(char**) * (prev_argc - argv_index - 1)); 106 | prev_argv[prev_argc - 1] = tmp; 107 | 108 | nonopt++; 109 | return 0; 110 | } 111 | } 112 | 113 | 114 | int getopt(int argc, char** argv, const char* optstr) 115 | { 116 | int c = 0; 117 | 118 | /* If we have new argv, reinitialize */ 119 | if(prev_argv != argv || prev_argc != argc) 120 | { 121 | /* Initialize variables */ 122 | prev_argv = argv; 123 | prev_argc = argc; 124 | argv_index = 1; 125 | argv_index2 = 1; 126 | opt_offset = 1; 127 | dashdash = 0; 128 | nonopt = 0; 129 | } 130 | 131 | /* Jump point in case we want to ignore the current argv_index */ 132 | getopt_top: 133 | 134 | /* Misc. initializations */ 135 | optarg = NULL; 136 | 137 | /* Dash-dash check */ 138 | if(argv[argv_index] && !strcmp(argv[argv_index], "--")) 139 | { 140 | dashdash = 1; 141 | increment_index(); 142 | } 143 | 144 | /* If we're at the end of argv, that's it. */ 145 | if(argv[argv_index] == NULL) 146 | { 147 | c = -1; 148 | } 149 | /* Are we looking at a string? Single dash is also a string */ 150 | else if(dashdash || argv[argv_index][0] != '-' || !strcmp(argv[argv_index], "-")) 151 | { 152 | /* If we want a string... */ 153 | if(optstr[0] == '-') 154 | { 155 | c = 1; 156 | optarg = argv[argv_index]; 157 | increment_index(); 158 | } 159 | /* If we really don't want it (we're in POSIX mode), we're done */ 160 | else if(optstr[0] == '+' || getenv("POSIXLY_CORRECT")) 161 | { 162 | c = -1; 163 | 164 | /* Everything else is a non-opt argument */ 165 | nonopt = argc - argv_index; 166 | } 167 | /* If we mildly don't want it, then move it back */ 168 | else 169 | { 170 | if(!permute_argv_once()) goto getopt_top; 171 | else c = -1; 172 | } 173 | } 174 | /* Otherwise we're looking at an option */ 175 | else 176 | { 177 | char* opt_ptr = NULL; 178 | 179 | /* Grab the option */ 180 | c = argv[argv_index][opt_offset++]; 181 | 182 | /* Is the option in the optstr? */ 183 | if(optstr[0] == '-') opt_ptr = strchr(optstr+1, c); 184 | else opt_ptr = strchr(optstr, c); 185 | /* Invalid argument */ 186 | if(!opt_ptr) 187 | { 188 | if(opterr) 189 | { 190 | fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c); 191 | } 192 | 193 | optopt = c; 194 | c = '?'; 195 | 196 | /* Move onto the next option */ 197 | increment_index(); 198 | } 199 | /* Option takes argument */ 200 | else if(opt_ptr[1] == ':') 201 | { 202 | /* ie, -oARGUMENT, -xxxoARGUMENT, etc. */ 203 | if(argv[argv_index][opt_offset] != '\0') 204 | { 205 | optarg = &argv[argv_index][opt_offset]; 206 | increment_index(); 207 | } 208 | /* ie, -o ARGUMENT (only if it's a required argument) */ 209 | else if(opt_ptr[2] != ':') 210 | { 211 | /* One of those "you're not expected to understand this" moment */ 212 | if(argv_index2 < argv_index) argv_index2 = argv_index; 213 | while(argv[++argv_index2] && argv[argv_index2][0] == '-'); 214 | optarg = argv[argv_index2]; 215 | 216 | /* Don't cross into the non-option argument list */ 217 | if(argv_index2 + nonopt >= prev_argc) optarg = NULL; 218 | 219 | /* Move onto the next option */ 220 | increment_index(); 221 | } 222 | else 223 | { 224 | /* Move onto the next option */ 225 | increment_index(); 226 | } 227 | 228 | /* In case we got no argument for an option with required argument */ 229 | if(optarg == NULL && opt_ptr[2] != ':') 230 | { 231 | optopt = c; 232 | c = '?'; 233 | 234 | if(opterr) 235 | { 236 | fprintf(stderr,"%s: option requires an argument -- %c\n", 237 | argv[0], optopt); 238 | } 239 | } 240 | } 241 | /* Option does not take argument */ 242 | else 243 | { 244 | /* Next argv_index */ 245 | if(argv[argv_index][opt_offset] == '\0') 246 | { 247 | increment_index(); 248 | } 249 | } 250 | } 251 | 252 | /* Calculate optind */ 253 | if(c == -1) 254 | { 255 | optind = argc - nonopt; 256 | } 257 | else 258 | { 259 | optind = argv_index; 260 | } 261 | 262 | return c; 263 | } 264 | 265 | 266 | /* vim:ts=3 267 | */ 268 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/src/win32_init.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW - An OpenGL library 3 | // Platform: Win32/WGL 4 | // API version: 3.0 5 | // WWW: http://www.glfw.org/ 6 | //------------------------------------------------------------------------ 7 | // Copyright (c) 2002-2006 Marcus Geelnard 8 | // Copyright (c) 2006-2010 Camilla Berglund 9 | // 10 | // This software is provided 'as-is', without any express or implied 11 | // warranty. In no event will the authors be held liable for any damages 12 | // arising from the use of this software. 13 | // 14 | // Permission is granted to anyone to use this software for any purpose, 15 | // including commercial applications, and to alter it and redistribute it 16 | // freely, subject to the following restrictions: 17 | // 18 | // 1. The origin of this software must not be misrepresented; you must not 19 | // claim that you wrote the original software. If you use this software 20 | // in a product, an acknowledgment in the product documentation would 21 | // be appreciated but is not required. 22 | // 23 | // 2. Altered source versions must be plainly marked as such, and must not 24 | // be misrepresented as being the original software. 25 | // 26 | // 3. This notice may not be removed or altered from any source 27 | // distribution. 28 | // 29 | //======================================================================== 30 | 31 | #include "internal.h" 32 | 33 | #include 34 | #include 35 | 36 | #ifdef __BORLANDC__ 37 | // With the Borland C++ compiler, we want to disable FPU exceptions 38 | #include 39 | #endif // __BORLANDC__ 40 | 41 | 42 | #if defined(_GLFW_BUILD_DLL) 43 | 44 | // GLFW DLL entry point 45 | // 46 | BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved) 47 | { 48 | return TRUE; 49 | } 50 | 51 | #endif // _GLFW_BUILD_DLL 52 | 53 | // Load necessary libraries (DLLs) 54 | // 55 | static GLboolean initLibraries(void) 56 | { 57 | #ifndef _GLFW_NO_DLOAD_WINMM 58 | // winmm.dll (for joystick and timer support) 59 | 60 | _glfw.win32.winmm.instance = LoadLibrary(L"winmm.dll"); 61 | if (!_glfw.win32.winmm.instance) 62 | return GL_FALSE; 63 | 64 | _glfw.win32.winmm.joyGetDevCaps = (JOYGETDEVCAPS_T) 65 | GetProcAddress(_glfw.win32.winmm.instance, "joyGetDevCapsW"); 66 | _glfw.win32.winmm.joyGetPos = (JOYGETPOS_T) 67 | GetProcAddress(_glfw.win32.winmm.instance, "joyGetPos"); 68 | _glfw.win32.winmm.joyGetPosEx = (JOYGETPOSEX_T) 69 | GetProcAddress(_glfw.win32.winmm.instance, "joyGetPosEx"); 70 | _glfw.win32.winmm.timeGetTime = (TIMEGETTIME_T) 71 | GetProcAddress(_glfw.win32.winmm.instance, "timeGetTime"); 72 | 73 | if (!_glfw.win32.winmm.joyGetDevCaps || 74 | !_glfw.win32.winmm.joyGetPos || 75 | !_glfw.win32.winmm.joyGetPosEx || 76 | !_glfw.win32.winmm.timeGetTime) 77 | { 78 | return GL_FALSE; 79 | } 80 | #endif // _GLFW_NO_DLOAD_WINMM 81 | 82 | _glfw.win32.user32.instance = LoadLibrary(L"user32.dll"); 83 | if (_glfw.win32.user32.instance) 84 | { 85 | _glfw.win32.user32.SetProcessDPIAware = (SETPROCESSDPIAWARE_T) 86 | GetProcAddress(_glfw.win32.user32.instance, "SetProcessDPIAware"); 87 | } 88 | 89 | _glfw.win32.dwmapi.instance = LoadLibrary(L"dwmapi.dll"); 90 | if (_glfw.win32.dwmapi.instance) 91 | { 92 | _glfw.win32.dwmapi.DwmIsCompositionEnabled = (DWMISCOMPOSITIONENABLED_T) 93 | GetProcAddress(_glfw.win32.dwmapi.instance, "DwmIsCompositionEnabled"); 94 | } 95 | 96 | return GL_TRUE; 97 | } 98 | 99 | // Unload used libraries (DLLs) 100 | // 101 | static void freeLibraries(void) 102 | { 103 | #ifndef _GLFW_NO_DLOAD_WINMM 104 | if (_glfw.win32.winmm.instance != NULL) 105 | { 106 | FreeLibrary(_glfw.win32.winmm.instance); 107 | _glfw.win32.winmm.instance = NULL; 108 | } 109 | #endif // _GLFW_NO_DLOAD_WINMM 110 | } 111 | 112 | 113 | ////////////////////////////////////////////////////////////////////////// 114 | ////// GLFW internal API ////// 115 | ////////////////////////////////////////////////////////////////////////// 116 | 117 | // Returns whether desktop compositing is enabled 118 | // 119 | BOOL _glfwIsCompositionEnabled(void) 120 | { 121 | BOOL enabled; 122 | 123 | if (!_glfw_DwmIsCompositionEnabled) 124 | return FALSE; 125 | 126 | if (_glfw_DwmIsCompositionEnabled(&enabled) != S_OK) 127 | return FALSE; 128 | 129 | return enabled; 130 | } 131 | 132 | // Returns a wide string version of the specified UTF-8 string 133 | // 134 | WCHAR* _glfwCreateWideStringFromUTF8(const char* source) 135 | { 136 | WCHAR* target; 137 | int length; 138 | 139 | length = MultiByteToWideChar(CP_UTF8, 0, source, -1, NULL, 0); 140 | if (!length) 141 | return NULL; 142 | 143 | target = (WCHAR*) malloc(sizeof(WCHAR) * (length + 1)); 144 | 145 | if (!MultiByteToWideChar(CP_UTF8, 0, source, -1, target, length + 1)) 146 | { 147 | free(target); 148 | return NULL; 149 | } 150 | 151 | return target; 152 | } 153 | 154 | // Returns a UTF-8 string version of the specified wide string 155 | // 156 | char* _glfwCreateUTF8FromWideString(const WCHAR* source) 157 | { 158 | char* target; 159 | int length; 160 | 161 | length = WideCharToMultiByte(CP_UTF8, 0, source, -1, NULL, 0, NULL, NULL); 162 | if (!length) 163 | return NULL; 164 | 165 | target = (char*) malloc(length + 1); 166 | 167 | if (!WideCharToMultiByte(CP_UTF8, 0, source, -1, target, length + 1, NULL, NULL)) 168 | { 169 | free(target); 170 | return NULL; 171 | } 172 | 173 | return target; 174 | } 175 | 176 | 177 | ////////////////////////////////////////////////////////////////////////// 178 | ////// GLFW platform API ////// 179 | ////////////////////////////////////////////////////////////////////////// 180 | 181 | int _glfwPlatformInit(void) 182 | { 183 | // To make SetForegroundWindow work as we want, we need to fiddle 184 | // with the FOREGROUNDLOCKTIMEOUT system setting (we do this as early 185 | // as possible in the hope of still being the foreground process) 186 | SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, 187 | &_glfw.win32.foregroundLockTimeout, 0); 188 | SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, UIntToPtr(0), 189 | SPIF_SENDCHANGE); 190 | 191 | if (!initLibraries()) 192 | return GL_FALSE; 193 | 194 | if (_glfw_SetProcessDPIAware) 195 | _glfw_SetProcessDPIAware(); 196 | 197 | #ifdef __BORLANDC__ 198 | // With the Borland C++ compiler, we want to disable FPU exceptions 199 | // (this is recommended for OpenGL applications under Windows) 200 | _control87(MCW_EM, MCW_EM); 201 | #endif 202 | 203 | if (!_glfwInitContextAPI()) 204 | return GL_FALSE; 205 | 206 | _glfwInitTimer(); 207 | 208 | _glfwInitJoysticks(); 209 | 210 | return GL_TRUE; 211 | } 212 | 213 | void _glfwPlatformTerminate(void) 214 | { 215 | if (_glfw.win32.classAtom) 216 | { 217 | UnregisterClass(_GLFW_WNDCLASSNAME, GetModuleHandle(NULL)); 218 | _glfw.win32.classAtom = 0; 219 | } 220 | 221 | _glfwTerminateContextAPI(); 222 | 223 | _glfwTerminateJoysticks(); 224 | 225 | freeLibraries(); 226 | 227 | // Restore previous FOREGROUNDLOCKTIMEOUT system setting 228 | SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, 229 | UIntToPtr(_glfw.win32.foregroundLockTimeout), 230 | SPIF_SENDCHANGE); 231 | } 232 | 233 | const char* _glfwPlatformGetVersionString(void) 234 | { 235 | const char* version = _GLFW_VERSION_FULL " Win32" 236 | #if defined(_GLFW_WGL) 237 | " WGL" 238 | #elif defined(_GLFW_EGL) 239 | " EGL" 240 | #endif 241 | #if defined(__MINGW32__) 242 | " MinGW" 243 | #elif defined(_MSC_VER) 244 | " VisualC " 245 | #elif defined(__BORLANDC__) 246 | " BorlandC" 247 | #endif 248 | #if !defined(_GLFW_NO_DLOAD_WINMM) 249 | " LoadLibrary(winmm)" 250 | #endif 251 | #if defined(_GLFW_BUILD_DLL) 252 | " DLL" 253 | #endif 254 | ; 255 | 256 | return version; 257 | } 258 | 259 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/src/x11_joystick.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW - An OpenGL library 3 | // Platform: X11 4 | // API version: 3.0 5 | // WWW: http://www.glfw.org/ 6 | //------------------------------------------------------------------------ 7 | // Copyright (c) 2002-2006 Marcus Geelnard 8 | // Copyright (c) 2006-2010 Camilla Berglund 9 | // 10 | // This software is provided 'as-is', without any express or implied 11 | // warranty. In no event will the authors be held liable for any damages 12 | // arising from the use of this software. 13 | // 14 | // Permission is granted to anyone to use this software for any purpose, 15 | // including commercial applications, and to alter it and redistribute it 16 | // freely, subject to the following restrictions: 17 | // 18 | // 1. The origin of this software must not be misrepresented; you must not 19 | // claim that you wrote the original software. If you use this software 20 | // in a product, an acknowledgment in the product documentation would 21 | // be appreciated but is not required. 22 | // 23 | // 2. Altered source versions must be plainly marked as such, and must not 24 | // be misrepresented as being the original software. 25 | // 26 | // 3. This notice may not be removed or altered from any source 27 | // distribution. 28 | // 29 | //======================================================================== 30 | 31 | #include "internal.h" 32 | 33 | #ifdef __linux__ 34 | #include 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #endif // __linux__ 46 | 47 | 48 | // Attempt to open the specified joystick device 49 | // 50 | static int openJoystickDevice(int joy, const char* path) 51 | { 52 | #ifdef __linux__ 53 | char axisCount, buttonCount; 54 | char name[256]; 55 | int fd, version; 56 | 57 | fd = open(path, O_RDONLY | O_NONBLOCK); 58 | if (fd == -1) 59 | return GL_FALSE; 60 | 61 | _glfw.x11.joystick[joy].fd = fd; 62 | 63 | // Verify that the joystick driver version is at least 1.0 64 | ioctl(fd, JSIOCGVERSION, &version); 65 | if (version < 0x010000) 66 | { 67 | // It's an old 0.x interface (we don't support it) 68 | close(fd); 69 | return GL_FALSE; 70 | } 71 | 72 | if (ioctl(fd, JSIOCGNAME(sizeof(name)), name) < 0) 73 | strncpy(name, "Unknown", sizeof(name)); 74 | 75 | _glfw.x11.joystick[joy].name = strdup(name); 76 | 77 | ioctl(fd, JSIOCGAXES, &axisCount); 78 | _glfw.x11.joystick[joy].axisCount = (int) axisCount; 79 | 80 | ioctl(fd, JSIOCGBUTTONS, &buttonCount); 81 | _glfw.x11.joystick[joy].buttonCount = (int) buttonCount; 82 | 83 | _glfw.x11.joystick[joy].axes = (float*) calloc(axisCount, sizeof(float)); 84 | _glfw.x11.joystick[joy].buttons = (unsigned char*) calloc(buttonCount, 1); 85 | 86 | _glfw.x11.joystick[joy].present = GL_TRUE; 87 | #endif // __linux__ 88 | 89 | return GL_TRUE; 90 | } 91 | 92 | // Polls for and processes events for all present joysticks 93 | // 94 | static void pollJoystickEvents(void) 95 | { 96 | #ifdef __linux__ 97 | int i; 98 | ssize_t result; 99 | struct js_event e; 100 | 101 | for (i = 0; i <= GLFW_JOYSTICK_LAST; i++) 102 | { 103 | if (!_glfw.x11.joystick[i].present) 104 | continue; 105 | 106 | // Read all queued events (non-blocking) 107 | for (;;) 108 | { 109 | errno = 0; 110 | result = read(_glfw.x11.joystick[i].fd, &e, sizeof(e)); 111 | 112 | if (errno == ENODEV) 113 | { 114 | free(_glfw.x11.joystick[i].axes); 115 | free(_glfw.x11.joystick[i].buttons); 116 | free(_glfw.x11.joystick[i].name); 117 | _glfw.x11.joystick[i].present = GL_FALSE; 118 | } 119 | 120 | if (result == -1) 121 | break; 122 | 123 | // We don't care if it's an init event or not 124 | e.type &= ~JS_EVENT_INIT; 125 | 126 | switch (e.type) 127 | { 128 | case JS_EVENT_AXIS: 129 | _glfw.x11.joystick[i].axes[e.number] = 130 | (float) e.value / 32767.0f; 131 | 132 | // We need to change the sign for the Y axes, so that 133 | // positive = up/forward, according to the GLFW spec. 134 | if (e.number & 1) 135 | { 136 | _glfw.x11.joystick[i].axes[e.number] = 137 | -_glfw.x11.joystick[i].axes[e.number]; 138 | } 139 | 140 | break; 141 | 142 | case JS_EVENT_BUTTON: 143 | _glfw.x11.joystick[i].buttons[e.number] = 144 | e.value ? GLFW_PRESS : GLFW_RELEASE; 145 | break; 146 | 147 | default: 148 | break; 149 | } 150 | } 151 | } 152 | #endif // __linux__ 153 | } 154 | 155 | 156 | ////////////////////////////////////////////////////////////////////////// 157 | ////// GLFW internal API ////// 158 | ////////////////////////////////////////////////////////////////////////// 159 | 160 | // Initialize joystick interface 161 | // 162 | int _glfwInitJoysticks(void) 163 | { 164 | #ifdef __linux__ 165 | int i, joy = 0; 166 | regex_t regex; 167 | DIR* dir; 168 | const char* dirs[] = 169 | { 170 | "/dev/input", 171 | "/dev" 172 | }; 173 | 174 | if (regcomp(®ex, "^js[0-9]\\+$", 0) != 0) 175 | { 176 | _glfwInputError(GLFW_PLATFORM_ERROR, "X11: Failed to compile regex"); 177 | return GL_FALSE; 178 | } 179 | 180 | for (i = 0; i < sizeof(dirs) / sizeof(dirs[0]); i++) 181 | { 182 | struct dirent* entry; 183 | 184 | dir = opendir(dirs[i]); 185 | if (!dir) 186 | continue; 187 | 188 | while ((entry = readdir(dir))) 189 | { 190 | char path[20]; 191 | regmatch_t match; 192 | 193 | if (regexec(®ex, entry->d_name, 1, &match, 0) != 0) 194 | continue; 195 | 196 | snprintf(path, sizeof(path), "%s/%s", dirs[i], entry->d_name); 197 | if (openJoystickDevice(joy, path)) 198 | joy++; 199 | } 200 | 201 | closedir(dir); 202 | } 203 | 204 | regfree(®ex); 205 | #endif // __linux__ 206 | 207 | return GL_TRUE; 208 | } 209 | 210 | // Close all opened joystick handles 211 | // 212 | void _glfwTerminateJoysticks(void) 213 | { 214 | #ifdef __linux__ 215 | int i; 216 | 217 | for (i = 0; i <= GLFW_JOYSTICK_LAST; i++) 218 | { 219 | if (_glfw.x11.joystick[i].present) 220 | { 221 | close(_glfw.x11.joystick[i].fd); 222 | free(_glfw.x11.joystick[i].axes); 223 | free(_glfw.x11.joystick[i].buttons); 224 | free(_glfw.x11.joystick[i].name); 225 | 226 | _glfw.x11.joystick[i].present = GL_FALSE; 227 | } 228 | } 229 | #endif // __linux__ 230 | } 231 | 232 | 233 | ////////////////////////////////////////////////////////////////////////// 234 | ////// GLFW platform API ////// 235 | ////////////////////////////////////////////////////////////////////////// 236 | 237 | int _glfwPlatformJoystickPresent(int joy) 238 | { 239 | pollJoystickEvents(); 240 | 241 | return _glfw.x11.joystick[joy].present; 242 | } 243 | 244 | const float* _glfwPlatformGetJoystickAxes(int joy, int* count) 245 | { 246 | pollJoystickEvents(); 247 | 248 | if (!_glfw.x11.joystick[joy].present) 249 | return NULL; 250 | 251 | *count = _glfw.x11.joystick[joy].axisCount; 252 | return _glfw.x11.joystick[joy].axes; 253 | } 254 | 255 | const unsigned char* _glfwPlatformGetJoystickButtons(int joy, int* count) 256 | { 257 | pollJoystickEvents(); 258 | 259 | if (!_glfw.x11.joystick[joy].present) 260 | return NULL; 261 | 262 | *count = _glfw.x11.joystick[joy].buttonCount; 263 | return _glfw.x11.joystick[joy].buttons; 264 | } 265 | 266 | const char* _glfwPlatformGetJoystickName(int joy) 267 | { 268 | pollJoystickEvents(); 269 | 270 | return _glfw.x11.joystick[joy].name; 271 | } 272 | 273 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/src/x11_platform.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW - An OpenGL library 3 | // Platform: X11 4 | // API version: 3.0 5 | // WWW: http://www.glfw.org/ 6 | //------------------------------------------------------------------------ 7 | // Copyright (c) 2002-2006 Marcus Geelnard 8 | // Copyright (c) 2006-2010 Camilla Berglund 9 | // 10 | // This software is provided 'as-is', without any express or implied 11 | // warranty. In no event will the authors be held liable for any damages 12 | // arising from the use of this software. 13 | // 14 | // Permission is granted to anyone to use this software for any purpose, 15 | // including commercial applications, and to alter it and redistribute it 16 | // freely, subject to the following restrictions: 17 | // 18 | // 1. The origin of this software must not be misrepresented; you must not 19 | // claim that you wrote the original software. If you use this software 20 | // in a product, an acknowledgment in the product documentation would 21 | // be appreciated but is not required. 22 | // 23 | // 2. Altered source versions must be plainly marked as such, and must not 24 | // be misrepresented as being the original software. 25 | // 26 | // 3. This notice may not be removed or altered from any source 27 | // distribution. 28 | // 29 | //======================================================================== 30 | 31 | #ifndef _x11_platform_h_ 32 | #define _x11_platform_h_ 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | // The Xf86VidMode extension provides fallback gamma control 42 | #include 43 | 44 | // The XRandR extension provides mode setting and gamma control 45 | #include 46 | 47 | // The XInput2 extension provides improved input events 48 | #include 49 | 50 | // The Xkb extension provides improved keyboard support 51 | #include 52 | 53 | #if defined(_GLFW_GLX) 54 | #define _GLFW_X11_CONTEXT_VISUAL window->glx.visual 55 | #include "glx_platform.h" 56 | #elif defined(_GLFW_EGL) 57 | #define _GLFW_X11_CONTEXT_VISUAL window->egl.visual 58 | #define _GLFW_EGL_NATIVE_WINDOW window->x11.handle 59 | #define _GLFW_EGL_NATIVE_DISPLAY _glfw.x11.display 60 | #include "egl_platform.h" 61 | #else 62 | #error "No supported context creation API selected" 63 | #endif 64 | 65 | #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowX11 x11 66 | #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryX11 x11 67 | #define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorX11 x11 68 | 69 | 70 | //======================================================================== 71 | // GLFW platform specific types 72 | //======================================================================== 73 | 74 | 75 | //------------------------------------------------------------------------ 76 | // Platform-specific window structure 77 | //------------------------------------------------------------------------ 78 | typedef struct _GLFWwindowX11 79 | { 80 | // Platform specific window resources 81 | Colormap colormap; // Window colormap 82 | Window handle; // Window handle 83 | 84 | // Various platform specific internal variables 85 | GLboolean overrideRedirect; // True if window is OverrideRedirect 86 | GLboolean cursorGrabbed; // True if cursor is currently grabbed 87 | GLboolean cursorHidden; // True if cursor is currently hidden 88 | 89 | // Cached position and size used to filter out duplicate events 90 | int width, height; 91 | int xpos, ypos; 92 | 93 | // The last received cursor position, regardless of source 94 | double cursorPosX, cursorPosY; 95 | // The last position the cursor was warped to by GLFW 96 | int warpPosX, warpPosY; 97 | 98 | } _GLFWwindowX11; 99 | 100 | 101 | //------------------------------------------------------------------------ 102 | // Platform-specific library global data for X11 103 | //------------------------------------------------------------------------ 104 | typedef struct _GLFWlibraryX11 105 | { 106 | Display* display; 107 | int screen; 108 | Window root; 109 | 110 | // Invisible cursor for hidden cursor mode 111 | Cursor cursor; 112 | XContext context; 113 | 114 | // Window manager atoms 115 | Atom WM_STATE; 116 | Atom WM_DELETE_WINDOW; 117 | Atom NET_WM_NAME; 118 | Atom NET_WM_ICON_NAME; 119 | Atom NET_WM_PID; 120 | Atom NET_WM_PING; 121 | Atom NET_WM_STATE; 122 | Atom NET_WM_STATE_FULLSCREEN; 123 | Atom NET_ACTIVE_WINDOW; 124 | Atom MOTIF_WM_HINTS; 125 | 126 | // Selection atoms 127 | Atom TARGETS; 128 | Atom MULTIPLE; 129 | Atom CLIPBOARD; 130 | Atom CLIPBOARD_MANAGER; 131 | Atom SAVE_TARGETS; 132 | Atom UTF8_STRING; 133 | Atom COMPOUND_STRING; 134 | Atom ATOM_PAIR; 135 | Atom GLFW_SELECTION; 136 | 137 | // True if window manager supports EWMH 138 | GLboolean hasEWMH; 139 | 140 | struct { 141 | GLboolean available; 142 | int eventBase; 143 | int errorBase; 144 | } vidmode; 145 | 146 | struct { 147 | GLboolean available; 148 | int eventBase; 149 | int errorBase; 150 | int versionMajor; 151 | int versionMinor; 152 | GLboolean gammaBroken; 153 | } randr; 154 | 155 | struct { 156 | int majorOpcode; 157 | int eventBase; 158 | int errorBase; 159 | int versionMajor; 160 | int versionMinor; 161 | } xkb; 162 | 163 | struct { 164 | GLboolean available; 165 | int majorOpcode; 166 | int eventBase; 167 | int errorBase; 168 | int versionMajor; 169 | int versionMinor; 170 | } xi; 171 | 172 | // LUT for mapping X11 key codes to GLFW key codes 173 | int keyCodeLUT[256]; 174 | 175 | struct { 176 | GLboolean changed; 177 | int timeout; 178 | int interval; 179 | int blanking; 180 | int exposure; 181 | } saver; 182 | 183 | struct { 184 | GLboolean monotonic; 185 | double resolution; 186 | uint64_t base; 187 | } timer; 188 | 189 | struct { 190 | char* string; 191 | } selection; 192 | 193 | struct { 194 | int present; 195 | int fd; 196 | float* axes; 197 | int axisCount; 198 | unsigned char* buttons; 199 | int buttonCount; 200 | char* name; 201 | } joystick[GLFW_JOYSTICK_LAST + 1]; 202 | 203 | } _GLFWlibraryX11; 204 | 205 | 206 | //------------------------------------------------------------------------ 207 | // Platform-specific monitor structure 208 | //------------------------------------------------------------------------ 209 | typedef struct _GLFWmonitorX11 210 | { 211 | RROutput output; 212 | RRCrtc crtc; 213 | RRMode oldMode; 214 | 215 | } _GLFWmonitorX11; 216 | 217 | 218 | //======================================================================== 219 | // Prototypes for platform specific internal functions 220 | //======================================================================== 221 | 222 | // Time 223 | void _glfwInitTimer(void); 224 | 225 | // Gamma 226 | void _glfwInitGammaRamp(void); 227 | 228 | // OpenGL support 229 | int _glfwInitContextAPI(void); 230 | void _glfwTerminateContextAPI(void); 231 | int _glfwCreateContext(_GLFWwindow* window, 232 | const _GLFWwndconfig* wndconfig, 233 | const _GLFWfbconfig* fbconfig); 234 | void _glfwDestroyContext(_GLFWwindow* window); 235 | 236 | // Fullscreen support 237 | void _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired); 238 | void _glfwRestoreVideoMode(_GLFWmonitor* monitor); 239 | 240 | // Joystick input 241 | int _glfwInitJoysticks(void); 242 | void _glfwTerminateJoysticks(void); 243 | 244 | // Unicode support 245 | long _glfwKeySym2Unicode(KeySym keysym); 246 | 247 | // Clipboard handling 248 | void _glfwHandleSelectionClear(XEvent* event); 249 | void _glfwHandleSelectionRequest(XEvent* event); 250 | void _glfwPushSelectionToManager(_GLFWwindow* window); 251 | 252 | // Window support 253 | _GLFWwindow* _glfwFindWindowByHandle(Window handle); 254 | unsigned long _glfwGetWindowProperty(Window window, 255 | Atom property, 256 | Atom type, 257 | unsigned char** value); 258 | 259 | #endif // _x11_platform_h_ 260 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/src/win32_platform.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW - An OpenGL library 3 | // Platform: Win32 4 | // API version: 3.0 5 | // WWW: http://www.glfw.org/ 6 | //------------------------------------------------------------------------ 7 | // Copyright (c) 2002-2006 Marcus Geelnard 8 | // Copyright (c) 2006-2010 Camilla Berglund 9 | // 10 | // This software is provided 'as-is', without any express or implied 11 | // warranty. In no event will the authors be held liable for any damages 12 | // arising from the use of this software. 13 | // 14 | // Permission is granted to anyone to use this software for any purpose, 15 | // including commercial applications, and to alter it and redistribute it 16 | // freely, subject to the following restrictions: 17 | // 18 | // 1. The origin of this software must not be misrepresented; you must not 19 | // claim that you wrote the original software. If you use this software 20 | // in a product, an acknowledgment in the product documentation would 21 | // be appreciated but is not required. 22 | // 23 | // 2. Altered source versions must be plainly marked as such, and must not 24 | // be misrepresented as being the original software. 25 | // 26 | // 3. This notice may not be removed or altered from any source 27 | // distribution. 28 | // 29 | //======================================================================== 30 | 31 | #ifndef _win32_platform_h_ 32 | #define _win32_platform_h_ 33 | 34 | 35 | // We don't need all the fancy stuff 36 | #ifndef NOMINMAX 37 | #define NOMINMAX 38 | #endif 39 | 40 | #ifndef VC_EXTRALEAN 41 | #define VC_EXTRALEAN 42 | #endif 43 | 44 | #ifndef WIN32_LEAN_AND_MEAN 45 | #define WIN32_LEAN_AND_MEAN 46 | #endif 47 | 48 | // This is a workaround for the fact that glfw3.h needs to export APIENTRY (to 49 | // correctly declare a GL_ARB_debug_output callback, for example) but windows.h 50 | // thinks it is the only one that gets to do so 51 | #undef APIENTRY 52 | 53 | // GLFW on Windows is Unicode only and does not work in MBCS mode 54 | #ifndef UNICODE 55 | #define UNICODE 56 | #endif 57 | 58 | // GLFW requires Windows XP 59 | #ifndef WINVER 60 | #define WINVER 0x0501 61 | #endif 62 | 63 | #include 64 | #include 65 | #include 66 | 67 | 68 | //======================================================================== 69 | // Hack: Define things that some windows.h variants don't 70 | //======================================================================== 71 | 72 | #ifndef WM_MOUSEHWHEEL 73 | #define WM_MOUSEHWHEEL 0x020E 74 | #endif 75 | #ifndef WM_DWMCOMPOSITIONCHANGED 76 | #define WM_DWMCOMPOSITIONCHANGED 0x031E 77 | #endif 78 | 79 | 80 | //======================================================================== 81 | // DLLs that are loaded at glfwInit() 82 | //======================================================================== 83 | 84 | // winmm.dll function pointer typedefs 85 | #ifndef _GLFW_NO_DLOAD_WINMM 86 | typedef MMRESULT (WINAPI * JOYGETDEVCAPS_T) (UINT,LPJOYCAPS,UINT); 87 | typedef MMRESULT (WINAPI * JOYGETPOS_T) (UINT,LPJOYINFO); 88 | typedef MMRESULT (WINAPI * JOYGETPOSEX_T) (UINT,LPJOYINFOEX); 89 | typedef DWORD (WINAPI * TIMEGETTIME_T) (void); 90 | #endif // _GLFW_NO_DLOAD_WINMM 91 | 92 | 93 | // winmm.dll shortcuts 94 | #ifndef _GLFW_NO_DLOAD_WINMM 95 | #define _glfw_joyGetDevCaps _glfw.win32.winmm.joyGetDevCaps 96 | #define _glfw_joyGetPos _glfw.win32.winmm.joyGetPos 97 | #define _glfw_joyGetPosEx _glfw.win32.winmm.joyGetPosEx 98 | #define _glfw_timeGetTime _glfw.win32.winmm.timeGetTime 99 | #else 100 | #define _glfw_joyGetDevCaps joyGetDevCaps 101 | #define _glfw_joyGetPos joyGetPos 102 | #define _glfw_joyGetPosEx joyGetPosEx 103 | #define _glfw_timeGetTime timeGetTime 104 | #endif // _GLFW_NO_DLOAD_WINMM 105 | 106 | // user32.dll function pointer typedefs 107 | typedef BOOL (WINAPI * SETPROCESSDPIAWARE_T)(void); 108 | #define _glfw_SetProcessDPIAware _glfw.win32.user32.SetProcessDPIAware 109 | 110 | // dwmapi.dll function pointer typedefs 111 | typedef HRESULT (WINAPI * DWMISCOMPOSITIONENABLED_T)(BOOL*); 112 | #define _glfw_DwmIsCompositionEnabled _glfw.win32.dwmapi.DwmIsCompositionEnabled 113 | 114 | 115 | // We use versioned window class names in order not to cause conflicts 116 | // between applications using different versions of GLFW 117 | #define _GLFW_WNDCLASSNAME L"GLFW30" 118 | 119 | #define _GLFW_RECREATION_NOT_NEEDED 0 120 | #define _GLFW_RECREATION_REQUIRED 1 121 | #define _GLFW_RECREATION_IMPOSSIBLE 2 122 | 123 | 124 | #if defined(_GLFW_WGL) 125 | #include "wgl_platform.h" 126 | #elif defined(_GLFW_EGL) 127 | #define _GLFW_EGL_NATIVE_WINDOW window->win32.handle 128 | #define _GLFW_EGL_NATIVE_DISPLAY EGL_DEFAULT_DISPLAY 129 | #include "egl_platform.h" 130 | #else 131 | #error "No supported context creation API selected" 132 | #endif 133 | 134 | #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowWin32 win32 135 | #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryWin32 win32 136 | #define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorWin32 win32 137 | 138 | 139 | //======================================================================== 140 | // GLFW platform specific types 141 | //======================================================================== 142 | 143 | 144 | //------------------------------------------------------------------------ 145 | // Platform-specific window structure 146 | //------------------------------------------------------------------------ 147 | typedef struct _GLFWwindowWin32 148 | { 149 | // Platform specific window resources 150 | HWND handle; // Window handle 151 | DWORD dwStyle; // Window styles used for window creation 152 | DWORD dwExStyle; // --"-- 153 | 154 | // Various platform specific internal variables 155 | GLboolean cursorCentered; 156 | GLboolean cursorInside; 157 | GLboolean cursorHidden; 158 | double oldCursorX, oldCursorY; 159 | } _GLFWwindowWin32; 160 | 161 | 162 | //------------------------------------------------------------------------ 163 | // Platform-specific library global data for Win32 164 | //------------------------------------------------------------------------ 165 | typedef struct _GLFWlibraryWin32 166 | { 167 | ATOM classAtom; 168 | DWORD foregroundLockTimeout; 169 | char* clipboardString; 170 | 171 | // Timer data 172 | struct { 173 | GLboolean hasPC; 174 | double resolution; 175 | unsigned int t0_32; 176 | __int64 t0_64; 177 | } timer; 178 | 179 | #ifndef _GLFW_NO_DLOAD_WINMM 180 | // winmm.dll 181 | struct { 182 | HINSTANCE instance; 183 | JOYGETDEVCAPS_T joyGetDevCaps; 184 | JOYGETPOS_T joyGetPos; 185 | JOYGETPOSEX_T joyGetPosEx; 186 | TIMEGETTIME_T timeGetTime; 187 | } winmm; 188 | #endif // _GLFW_NO_DLOAD_WINMM 189 | 190 | // user32.dll 191 | struct { 192 | HINSTANCE instance; 193 | SETPROCESSDPIAWARE_T SetProcessDPIAware; 194 | } user32; 195 | 196 | // dwmapi.dll 197 | struct { 198 | HINSTANCE instance; 199 | DWMISCOMPOSITIONENABLED_T DwmIsCompositionEnabled; 200 | } dwmapi; 201 | 202 | struct { 203 | float axes[6]; 204 | unsigned char buttons[36]; // 32 buttons plus one hat 205 | char* name; 206 | } joystick[GLFW_JOYSTICK_LAST + 1]; 207 | 208 | } _GLFWlibraryWin32; 209 | 210 | 211 | //------------------------------------------------------------------------ 212 | // Platform-specific monitor structure 213 | //------------------------------------------------------------------------ 214 | typedef struct _GLFWmonitorWin32 215 | { 216 | // This size matches the static size of DISPLAY_DEVICE.DeviceName 217 | WCHAR name[32]; 218 | 219 | } _GLFWmonitorWin32; 220 | 221 | 222 | //======================================================================== 223 | // Prototypes for platform specific internal functions 224 | //======================================================================== 225 | 226 | // Desktop compositing 227 | BOOL _glfwIsCompositionEnabled(void); 228 | 229 | // Wide strings 230 | WCHAR* _glfwCreateWideStringFromUTF8(const char* source); 231 | char* _glfwCreateUTF8FromWideString(const WCHAR* source); 232 | 233 | // Time 234 | void _glfwInitTimer(void); 235 | 236 | // Joystick input 237 | void _glfwInitJoysticks(void); 238 | void _glfwTerminateJoysticks(void); 239 | 240 | // OpenGL support 241 | int _glfwInitContextAPI(void); 242 | void _glfwTerminateContextAPI(void); 243 | int _glfwCreateContext(_GLFWwindow* window, 244 | const _GLFWwndconfig* wndconfig, 245 | const _GLFWfbconfig* fbconfig); 246 | void _glfwDestroyContext(_GLFWwindow* window); 247 | int _glfwAnalyzeContext(const _GLFWwindow* window, 248 | const _GLFWwndconfig* wndconfig, 249 | const _GLFWfbconfig* fbconfig); 250 | 251 | // Fullscreen support 252 | GLboolean _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired); 253 | void _glfwRestoreVideoMode(_GLFWmonitor* monitor); 254 | 255 | 256 | #endif // _win32_platform_h_ 257 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/src/win32_monitor.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW - An OpenGL library 3 | // Platform: X11 (Unix) 4 | // API version: 3.0 5 | // WWW: http://www.glfw.org/ 6 | //------------------------------------------------------------------------ 7 | // Copyright (c) 2002-2006 Marcus Geelnard 8 | // Copyright (c) 2006-2010 Camilla Berglund 9 | // 10 | // This software is provided 'as-is', without any express or implied 11 | // warranty. In no event will the authors be held liable for any damages 12 | // arising from the use of this software. 13 | // 14 | // Permission is granted to anyone to use this software for any purpose, 15 | // including commercial applications, and to alter it and redistribute it 16 | // freely, subject to the following restrictions: 17 | // 18 | // 1. The origin of this software must not be misrepresented; you must not 19 | // claim that you wrote the original software. If you use this software 20 | // in a product, an acknowledgment in the product documentation would 21 | // be appreciated but is not required. 22 | // 23 | // 2. Altered source versions must be plainly marked as such, and must not 24 | // be misrepresented as being the original software. 25 | // 26 | // 3. This notice may not be removed or altered from any source 27 | // distribution. 28 | // 29 | //======================================================================== 30 | 31 | #include "internal.h" 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | // These constants are missing on MinGW 39 | #ifndef EDS_ROTATEDMODE 40 | #define EDS_ROTATEDMODE 0x00000004 41 | #endif 42 | #ifndef DISPLAY_DEVICE_ACTIVE 43 | #define DISPLAY_DEVICE_ACTIVE 0x00000001 44 | #endif 45 | 46 | 47 | ////////////////////////////////////////////////////////////////////////// 48 | ////// GLFW internal API ////// 49 | ////////////////////////////////////////////////////////////////////////// 50 | 51 | // Change the current video mode 52 | // 53 | GLboolean _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired) 54 | { 55 | GLFWvidmode current; 56 | const GLFWvidmode* best; 57 | DEVMODE dm; 58 | 59 | best = _glfwChooseVideoMode(monitor, desired); 60 | 61 | _glfwPlatformGetVideoMode(monitor, ¤t); 62 | if (_glfwCompareVideoModes(¤t, best) == 0) 63 | return GL_TRUE; 64 | 65 | ZeroMemory(&dm, sizeof(dm)); 66 | dm.dmSize = sizeof(DEVMODE); 67 | dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | 68 | DM_DISPLAYFREQUENCY; 69 | dm.dmPelsWidth = best->width; 70 | dm.dmPelsHeight = best->height; 71 | dm.dmBitsPerPel = best->redBits + best->greenBits + best->blueBits; 72 | dm.dmDisplayFrequency = best->refreshRate; 73 | 74 | if (dm.dmBitsPerPel < 15 || dm.dmBitsPerPel >= 24) 75 | dm.dmBitsPerPel = 32; 76 | 77 | if (ChangeDisplaySettingsEx(monitor->win32.name, 78 | &dm, 79 | NULL, 80 | CDS_FULLSCREEN, 81 | NULL) != DISP_CHANGE_SUCCESSFUL) 82 | { 83 | _glfwInputError(GLFW_PLATFORM_ERROR, "Win32: Failed to set video mode"); 84 | return GL_FALSE; 85 | } 86 | 87 | return GL_TRUE; 88 | } 89 | 90 | // Restore the previously saved (original) video mode 91 | // 92 | void _glfwRestoreVideoMode(_GLFWmonitor* monitor) 93 | { 94 | ChangeDisplaySettingsEx(monitor->win32.name, 95 | NULL, NULL, CDS_FULLSCREEN, NULL); 96 | } 97 | 98 | 99 | ////////////////////////////////////////////////////////////////////////// 100 | ////// GLFW platform API ////// 101 | ////////////////////////////////////////////////////////////////////////// 102 | 103 | _GLFWmonitor** _glfwPlatformGetMonitors(int* count) 104 | { 105 | int size = 0, found = 0; 106 | _GLFWmonitor** monitors = NULL; 107 | DWORD adapterIndex = 0; 108 | int primaryIndex = 0; 109 | 110 | *count = 0; 111 | 112 | for (;;) 113 | { 114 | DISPLAY_DEVICE adapter, display; 115 | char* name; 116 | HDC dc; 117 | 118 | ZeroMemory(&adapter, sizeof(DISPLAY_DEVICE)); 119 | adapter.cb = sizeof(DISPLAY_DEVICE); 120 | 121 | if (!EnumDisplayDevices(NULL, adapterIndex, &adapter, 0)) 122 | break; 123 | 124 | adapterIndex++; 125 | 126 | if ((adapter.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER) || 127 | !(adapter.StateFlags & DISPLAY_DEVICE_ACTIVE)) 128 | { 129 | continue; 130 | } 131 | 132 | if (found == size) 133 | { 134 | if (size) 135 | size *= 2; 136 | else 137 | size = 4; 138 | 139 | monitors = (_GLFWmonitor**) realloc(monitors, sizeof(_GLFWmonitor*) * size); 140 | } 141 | 142 | ZeroMemory(&display, sizeof(DISPLAY_DEVICE)); 143 | display.cb = sizeof(DISPLAY_DEVICE); 144 | 145 | EnumDisplayDevices(adapter.DeviceName, 0, &display, 0); 146 | dc = CreateDC(L"DISPLAY", display.DeviceString, NULL, NULL); 147 | 148 | if (adapter.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) 149 | primaryIndex = found; 150 | 151 | name = _glfwCreateUTF8FromWideString(display.DeviceString); 152 | if (!name) 153 | { 154 | _glfwDestroyMonitors(monitors, found); 155 | _glfwInputError(GLFW_PLATFORM_ERROR, 156 | "Failed to convert string to UTF-8"); 157 | 158 | free(monitors); 159 | return NULL; 160 | } 161 | 162 | monitors[found] = _glfwCreateMonitor(name, 163 | GetDeviceCaps(dc, HORZSIZE), 164 | GetDeviceCaps(dc, VERTSIZE)); 165 | 166 | free(name); 167 | DeleteDC(dc); 168 | 169 | wcscpy(monitors[found]->win32.name, adapter.DeviceName); 170 | found++; 171 | } 172 | 173 | if (primaryIndex > 0) 174 | { 175 | _GLFWmonitor* temp = monitors[0]; 176 | monitors[0] = monitors[primaryIndex]; 177 | monitors[primaryIndex] = temp; 178 | } 179 | 180 | *count = found; 181 | return monitors; 182 | } 183 | 184 | GLboolean _glfwPlatformIsSameMonitor(_GLFWmonitor* first, _GLFWmonitor* second) 185 | { 186 | return wcscmp(first->win32.name, second->win32.name) == 0; 187 | } 188 | 189 | void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos) 190 | { 191 | DEVMODE settings; 192 | ZeroMemory(&settings, sizeof(DEVMODE)); 193 | settings.dmSize = sizeof(DEVMODE); 194 | 195 | EnumDisplaySettingsEx(monitor->win32.name, 196 | ENUM_CURRENT_SETTINGS, 197 | &settings, 198 | EDS_ROTATEDMODE); 199 | 200 | if (xpos) 201 | *xpos = settings.dmPosition.x; 202 | if (ypos) 203 | *ypos = settings.dmPosition.y; 204 | } 205 | 206 | GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found) 207 | { 208 | int modeIndex = 0, count = 0; 209 | GLFWvidmode* result = NULL; 210 | 211 | *found = 0; 212 | 213 | for (;;) 214 | { 215 | int i; 216 | GLFWvidmode mode; 217 | DEVMODE dm; 218 | 219 | ZeroMemory(&dm, sizeof(DEVMODE)); 220 | dm.dmSize = sizeof(DEVMODE); 221 | 222 | if (!EnumDisplaySettings(monitor->win32.name, modeIndex, &dm)) 223 | break; 224 | 225 | modeIndex++; 226 | 227 | if (dm.dmBitsPerPel < 15) 228 | { 229 | // Skip modes with less than 15 BPP 230 | continue; 231 | } 232 | 233 | mode.width = dm.dmPelsWidth; 234 | mode.height = dm.dmPelsHeight; 235 | mode.refreshRate = dm.dmDisplayFrequency; 236 | _glfwSplitBPP(dm.dmBitsPerPel, 237 | &mode.redBits, 238 | &mode.greenBits, 239 | &mode.blueBits); 240 | 241 | for (i = 0; i < *found; i++) 242 | { 243 | if (_glfwCompareVideoModes(result + i, &mode) == 0) 244 | break; 245 | } 246 | 247 | if (i < *found) 248 | { 249 | // This is a duplicate, so skip it 250 | continue; 251 | } 252 | 253 | if (*found == count) 254 | { 255 | if (count) 256 | count *= 2; 257 | else 258 | count = 128; 259 | 260 | result = (GLFWvidmode*) realloc(result, count * sizeof(GLFWvidmode)); 261 | } 262 | 263 | result[*found] = mode; 264 | (*found)++; 265 | } 266 | 267 | return result; 268 | } 269 | 270 | void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode) 271 | { 272 | DEVMODE dm; 273 | 274 | ZeroMemory(&dm, sizeof(DEVMODE)); 275 | dm.dmSize = sizeof(DEVMODE); 276 | 277 | EnumDisplaySettings(monitor->win32.name, ENUM_CURRENT_SETTINGS, &dm); 278 | 279 | mode->width = dm.dmPelsWidth; 280 | mode->height = dm.dmPelsHeight; 281 | mode->refreshRate = dm.dmDisplayFrequency; 282 | _glfwSplitBPP(dm.dmBitsPerPel, 283 | &mode->redBits, 284 | &mode->greenBits, 285 | &mode->blueBits); 286 | } 287 | 288 | -------------------------------------------------------------------------------- /include/m_dist.h: -------------------------------------------------------------------------------- 1 | /*====================================================================== 2 | Maratis Tiny C Library 3 | version 1.0 4 | ------------------------------------------------------------------------ 5 | Copyright (c) 2015 Anael Seghezzi 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 | Fast distance transform and Voronoi: 29 | 30 | to create the implementation, 31 | #define M_DIST_IMPLEMENTATION 32 | in *one* C/CPP file that includes this file. 33 | 34 | optional: 35 | include this file after *m_image.h* to enable m_image helpers 36 | */ 37 | 38 | #ifndef M_DIST_H 39 | #define M_DIST_H 40 | 41 | #define M_DIST_VERSION 1 42 | 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif 46 | 47 | #ifndef MDAPI 48 | #define MDAPI extern 49 | #endif 50 | 51 | #define M_DIST_MAX 1e20f 52 | 53 | /* raw distance functions 54 | dest: squared distance */ 55 | MDAPI void m_dist_transform_1d(float *dest, float *src, int count); 56 | MDAPI void m_dist_transform_2d(float *dest, float *src, int width, int height); 57 | 58 | /* raw voronoi distance functions 59 | destd: squared distance, desti: closest src index */ 60 | MDAPI void m_voronoi_transform_1d(float *destd, int *desti, float *src, int count); 61 | MDAPI void m_voronoi_transform_2d(float *destd, int *desti, float *src, int width, int height); 62 | 63 | /* image distance transform */ 64 | #ifdef M_IMAGE_VERSION 65 | 66 | MDAPI void m_image_dist_mask_init(struct m_image *dest, const struct m_image *src); /* initialize a valid distance map from a ubyte mask */ 67 | MDAPI void m_image_dist_transform(struct m_image *dest, const struct m_image *src); 68 | MDAPI void m_image_voronoi_transform(struct m_image *destd, struct m_image *desti, const struct m_image *src); 69 | MDAPI void m_image_voronoi_fill(struct m_image *dest, const struct m_image *src, const struct m_image *srci); 70 | 71 | #endif /* M_IMAGE_VERSION */ 72 | 73 | #ifdef __cplusplus 74 | } 75 | #endif 76 | /* 77 | ----------------------------------------------------------------------*/ 78 | #endif /* M_DIST_H */ 79 | 80 | #ifdef M_DIST_IMPLEMENTATION 81 | 82 | #include 83 | #include 84 | #include 85 | #include 86 | #include 87 | 88 | /* From paper: 89 | Distance Transforms of Sampled Functions 90 | by Pedro F. Felzenszwalb and Daniel P. Huttenlocher */ 91 | 92 | #define M_DIST_T()\ 93 | v[0] = 0;\ 94 | z[0] = -M_DIST_MAX;\ 95 | z[1] = M_DIST_MAX;\ 96 | k = 0;\ 97 | for (q = 1; q < count; q++) {\ 98 | float s;\ 99 | while (1) {\ 100 | s = (((double)src[q] + q * q) - ((double)src[v[k]] + v[k] * v[k])) / (double)(2 * q - 2 * v[k]);\ 101 | if (s > z[k])\ 102 | break;\ 103 | k--;\ 104 | }\ 105 | k++;\ 106 | v[k] = q;\ 107 | z[k] = s;\ 108 | z[k+1] = M_DIST_MAX;\ 109 | } 110 | 111 | void m_dist_transform_1d(float *dest, float *src, int count) 112 | { 113 | int *v = (int *)malloc(count * sizeof(int)); 114 | float *z = (float *)malloc((count + 1) * sizeof(float)); 115 | int q, k; 116 | 117 | M_DIST_T() 118 | 119 | k = 0; 120 | for (q = 0; q < count; q++) { 121 | while(z[k+1] < q) k++; 122 | dest[q] = (q - v[k]) * (q - v[k]) + src[v[k]]; 123 | } 124 | 125 | free(z); 126 | free(v); 127 | } 128 | 129 | void m_voronoi_transform_1d(float *destd, int *desti, float *src, int count) 130 | { 131 | int *v = (int *)malloc(count * sizeof(int)); 132 | float *z = (float *)malloc((count + 1) * sizeof(float)); 133 | int q, k; 134 | 135 | M_DIST_T() 136 | 137 | k = 0; 138 | for (q = 0; q < count; q++) { 139 | while (z[k+1] < q) k++; 140 | destd[q] = (q - v[k]) * (q - v[k]) + src[v[k]]; 141 | desti[q] = v[k]; 142 | } 143 | 144 | free(z); 145 | free(v); 146 | } 147 | 148 | void m_dist_transform_2d(float *dest, float *src, int width, int height) 149 | { 150 | 151 | float *tmp1 = (float *)malloc(M_MAX(width, height) * sizeof(float)); 152 | float *tmp2 = (float *)malloc(M_MAX(width, height) * sizeof(float)); 153 | int x, y; 154 | 155 | /* vertical pass */ 156 | for (x = 0; x < width; x++) { 157 | 158 | /* fill vertical line */ 159 | for (y = 0; y < height; y++) 160 | tmp1[y] = *(src + width * y + x); 161 | 162 | m_dist_transform_1d(tmp2, tmp1, height); 163 | 164 | /* copy the result */ 165 | for (y = 0; y < height; y++) 166 | *(dest + width * y + x) = tmp2[y]; 167 | } 168 | 169 | /* horizontal pass */ 170 | for (y = 0; y < height; y++) { 171 | memcpy(tmp1, dest + width * y, width * sizeof(float)); 172 | m_dist_transform_1d(dest + width * y, tmp1, width); 173 | } 174 | 175 | free(tmp2); 176 | free(tmp1); 177 | 178 | } 179 | 180 | void m_voronoi_transform_2d(float *destd, int *desti, float *src, int width, int height) 181 | { 182 | int maxs = M_MAX(width, height); 183 | float *tmp1 = (float *)malloc(maxs * sizeof(float)); 184 | float *tmp2 = (float *)malloc(maxs * sizeof(float)); 185 | int *tmpi1 = (int *)malloc(maxs * sizeof(int)); 186 | int *tmpi2 = (int *)malloc(width * sizeof(int)); 187 | int x, y; 188 | 189 | /* vertical pass */ 190 | for (x = 0; x < width; x++) { 191 | 192 | /* fill vertical line */ 193 | for (y = 0; y < height; y++) 194 | tmp1[y] = *(src + width * y + x); 195 | 196 | m_voronoi_transform_1d(tmp2, tmpi1, tmp1, height); 197 | 198 | /* copy the result */ 199 | for (y = 0; y < height; y++) { 200 | *(destd + width * y + x) = tmp2[y]; 201 | *(desti + width * y + x) = tmpi1[y]; 202 | } 203 | } 204 | 205 | /* horizontal pass */ 206 | for (y = 0; y < height; y++) { 207 | 208 | /* copy distance and index of current line */ 209 | memcpy(tmp1, destd + width * y, width * sizeof(float)); 210 | memcpy(tmpi2, desti + width * y, width * sizeof(int)); 211 | 212 | m_voronoi_transform_1d(destd + width * y, tmpi1, tmp1, width); 213 | 214 | /* compute 2d closest pixel index */ 215 | for (x = 0; x < width; x++) { 216 | int _x = tmpi1[x]; 217 | int _y = tmpi2[_x]; 218 | *(desti + width * y + x) = _y * width + _x; 219 | } 220 | } 221 | 222 | free(tmpi2); 223 | free(tmpi1); 224 | free(tmp2); 225 | free(tmp1); 226 | } 227 | 228 | #ifdef M_IMAGE_VERSION 229 | 230 | void m_image_dist_mask_init(struct m_image *dest, const struct m_image *src) 231 | { 232 | float *dest_data; 233 | unsigned char *src_data; 234 | int width = src->width; 235 | int height = src->height; 236 | int size = src->size; 237 | int i; 238 | 239 | assert(src->size > 0 && src->type == M_UBYTE && src->comp == 1); 240 | m_image_create(dest, M_FLOAT, width, height, 1); 241 | 242 | dest_data = (float *)dest->data; 243 | src_data = (unsigned char *)src->data; 244 | 245 | /* init from mask */ 246 | for (i = 0; i < size; i++) 247 | dest_data[i] = src_data[i] < 128 ? M_DIST_MAX : 0; 248 | } 249 | 250 | void m_image_dist_transform(struct m_image *dest, const struct m_image *src) 251 | { 252 | float *dest_data; 253 | int width = src->width; 254 | int height = src->height; 255 | int size = src->size; 256 | int i; 257 | 258 | assert(src->size > 0 && src->type == M_FLOAT && src->comp == 1); 259 | m_image_create(dest, M_FLOAT, width, height, 1); 260 | dest_data = (float *)dest->data; 261 | 262 | /* distance transform */ 263 | m_dist_transform_2d(dest_data, (float *)src->data, width, height); 264 | 265 | for (i = 0; i < size; i++) 266 | dest_data[i] = sqrtf(dest_data[i]); 267 | } 268 | 269 | void m_image_voronoi_transform(struct m_image *destd, struct m_image *desti, const struct m_image *src) 270 | { 271 | float *dest_data; 272 | int width = src->width; 273 | int height = src->height; 274 | int size = src->size; 275 | int i; 276 | 277 | assert(src->size > 0 && src->type == M_FLOAT && src->comp == 1); 278 | m_image_create(destd, M_FLOAT, width, height, 1); 279 | m_image_create(desti, M_INT, width, height, 1); 280 | dest_data = (float *)destd->data; 281 | 282 | /* distance transform */ 283 | m_voronoi_transform_2d(dest_data, (int *)desti->data, (float *)src->data, width, height); 284 | 285 | for (i = 0; i < size; i++) 286 | dest_data[i] = sqrtf(dest_data[i]); 287 | } 288 | 289 | void m_image_voronoi_fill(struct m_image *dest, const struct m_image *src, const struct m_image *srci) 290 | { 291 | #define M_VORO_FILL(T)\ 292 | {\ 293 | T *sData = (T *)src->data;\ 294 | T *dData = (T *)dest->data;\ 295 | int i, c;\ 296 | for (i = 0; i < size; i++) {\ 297 | for (c = 0; c < comp; c++) {\ 298 | (*dData) = sData[(*datai) * comp + c];\ 299 | dData++;\ 300 | }\ 301 | datai++;\ 302 | }\ 303 | } 304 | 305 | int *datai = (int *)srci->data; 306 | int comp = src->comp; 307 | int size = srci->size; 308 | 309 | m_image_create(dest, src->type, src->width, src->height, src->comp); 310 | 311 | switch(src->type) 312 | { 313 | case M_BYTE: 314 | case M_UBYTE: 315 | M_VORO_FILL(char); 316 | break; 317 | case M_SHORT: 318 | case M_USHORT: 319 | case M_HALF: 320 | M_VORO_FILL(short); 321 | break; 322 | case M_INT: 323 | case M_UINT: 324 | M_VORO_FILL(int); 325 | break; 326 | case M_FLOAT: 327 | M_VORO_FILL(float); 328 | break; 329 | default: 330 | assert(0); 331 | break; 332 | } 333 | 334 | #undef M_VORO_FILL 335 | } 336 | 337 | #endif /* M_IMAGE_VERSION */ 338 | 339 | #endif /* M_DIST_IMPLEMENTATION */ -------------------------------------------------------------------------------- /tests/3rdparty/glfw/src/nsgl_context.m: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW - An OpenGL library 3 | // Platform: Cocoa/NSOpenGL 4 | // API Version: 3.0 5 | // WWW: http://www.glfw.org/ 6 | //------------------------------------------------------------------------ 7 | // Copyright (c) 2009-2010 Camilla Berglund 8 | // 9 | // This software is provided 'as-is', without any express or implied 10 | // warranty. In no event will the authors be held liable for any damages 11 | // arising from the use of this software. 12 | // 13 | // Permission is granted to anyone to use this software for any purpose, 14 | // including commercial applications, and to alter it and redistribute it 15 | // freely, subject to the following restrictions: 16 | // 17 | // 1. The origin of this software must not be misrepresented; you must not 18 | // claim that you wrote the original software. If you use this software 19 | // in a product, an acknowledgment in the product documentation would 20 | // be appreciated but is not required. 21 | // 22 | // 2. Altered source versions must be plainly marked as such, and must not 23 | // be misrepresented as being the original software. 24 | // 25 | // 3. This notice may not be removed or altered from any source 26 | // distribution. 27 | // 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #include 33 | 34 | 35 | ////////////////////////////////////////////////////////////////////////// 36 | ////// GLFW internal API ////// 37 | ////////////////////////////////////////////////////////////////////////// 38 | 39 | // Initialize OpenGL support 40 | // 41 | int _glfwInitContextAPI(void) 42 | { 43 | if (pthread_key_create(&_glfw.nsgl.current, NULL) != 0) 44 | { 45 | _glfwInputError(GLFW_PLATFORM_ERROR, 46 | "NSOpenGL: Failed to create context TLS"); 47 | return GL_FALSE; 48 | } 49 | 50 | _glfw.nsgl.framework = 51 | CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl")); 52 | if (_glfw.nsgl.framework == NULL) 53 | { 54 | _glfwInputError(GLFW_PLATFORM_ERROR, 55 | "NSGL: Failed to locate OpenGL framework"); 56 | return GL_FALSE; 57 | } 58 | 59 | return GL_TRUE; 60 | } 61 | 62 | // Terminate OpenGL support 63 | // 64 | void _glfwTerminateContextAPI(void) 65 | { 66 | pthread_key_delete(_glfw.nsgl.current); 67 | } 68 | 69 | // Create the OpenGL context 70 | // 71 | int _glfwCreateContext(_GLFWwindow* window, 72 | const _GLFWwndconfig* wndconfig, 73 | const _GLFWfbconfig* fbconfig) 74 | { 75 | unsigned int attributeCount = 0; 76 | 77 | // Mac OS X needs non-zero color size, so set resonable values 78 | int colorBits = fbconfig->redBits + fbconfig->greenBits + fbconfig->blueBits; 79 | if (colorBits == 0) 80 | colorBits = 24; 81 | else if (colorBits < 15) 82 | colorBits = 15; 83 | 84 | if (wndconfig->clientAPI == GLFW_OPENGL_ES_API) 85 | { 86 | _glfwInputError(GLFW_VERSION_UNAVAILABLE, 87 | "NSOpenGL: This API does not support OpenGL ES"); 88 | return GL_FALSE; 89 | } 90 | 91 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 92 | // Fail if any OpenGL version above 2.1 other than 3.2 was requested 93 | if (wndconfig->glMajor > 3 || 94 | (wndconfig->glMajor == 3 && wndconfig->glMinor != 2)) 95 | { 96 | _glfwInputError(GLFW_VERSION_UNAVAILABLE, 97 | "NSOpenGL: The targeted version of Mac OS X does not " 98 | "support any OpenGL version above 2.1 except 3.2"); 99 | return GL_FALSE; 100 | } 101 | 102 | if (wndconfig->glMajor > 2) 103 | { 104 | if (!wndconfig->glForward) 105 | { 106 | _glfwInputError(GLFW_VERSION_UNAVAILABLE, 107 | "NSOpenGL: The targeted version of Mac OS X only " 108 | "supports OpenGL 3.2 contexts if they are " 109 | "forward-compatible"); 110 | return GL_FALSE; 111 | } 112 | 113 | if (wndconfig->glProfile != GLFW_OPENGL_CORE_PROFILE) 114 | { 115 | _glfwInputError(GLFW_VERSION_UNAVAILABLE, 116 | "NSOpenGL: The targeted version of Mac OS X only " 117 | "supports OpenGL 3.2 contexts if they use the " 118 | "core profile"); 119 | return GL_FALSE; 120 | } 121 | } 122 | #else 123 | // Fail if OpenGL 3.0 or above was requested 124 | if (wndconfig->glMajor > 2) 125 | { 126 | _glfwInputError(GLFW_VERSION_UNAVAILABLE, 127 | "NSOpenGL: The targeted version of Mac OS X does not " 128 | "support OpenGL version 3.0 or above"); 129 | return GL_FALSE; 130 | } 131 | #endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/ 132 | 133 | // Fail if a robustness strategy was requested 134 | if (wndconfig->glRobustness) 135 | { 136 | _glfwInputError(GLFW_VERSION_UNAVAILABLE, 137 | "NSOpenGL: Mac OS X does not support OpenGL robustness " 138 | "strategies"); 139 | return GL_FALSE; 140 | } 141 | 142 | #define ADD_ATTR(x) { attributes[attributeCount++] = x; } 143 | #define ADD_ATTR2(x, y) { ADD_ATTR(x); ADD_ATTR(y); } 144 | 145 | // Arbitrary array size here 146 | NSOpenGLPixelFormatAttribute attributes[40]; 147 | 148 | ADD_ATTR(NSOpenGLPFADoubleBuffer); 149 | ADD_ATTR(NSOpenGLPFAClosestPolicy); 150 | 151 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 152 | if (wndconfig->glMajor > 2) 153 | ADD_ATTR2(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core); 154 | #endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/ 155 | 156 | ADD_ATTR2(NSOpenGLPFAColorSize, colorBits); 157 | 158 | if (fbconfig->alphaBits > 0) 159 | ADD_ATTR2(NSOpenGLPFAAlphaSize, fbconfig->alphaBits); 160 | 161 | if (fbconfig->depthBits > 0) 162 | ADD_ATTR2(NSOpenGLPFADepthSize, fbconfig->depthBits); 163 | 164 | if (fbconfig->stencilBits > 0) 165 | ADD_ATTR2(NSOpenGLPFAStencilSize, fbconfig->stencilBits); 166 | 167 | int accumBits = fbconfig->accumRedBits + fbconfig->accumGreenBits + 168 | fbconfig->accumBlueBits + fbconfig->accumAlphaBits; 169 | 170 | if (accumBits > 0) 171 | ADD_ATTR2(NSOpenGLPFAAccumSize, accumBits); 172 | 173 | if (fbconfig->auxBuffers > 0) 174 | ADD_ATTR2(NSOpenGLPFAAuxBuffers, fbconfig->auxBuffers); 175 | 176 | if (fbconfig->stereo) 177 | ADD_ATTR(NSOpenGLPFAStereo); 178 | 179 | if (fbconfig->samples > 0) 180 | { 181 | ADD_ATTR2(NSOpenGLPFASampleBuffers, 1); 182 | ADD_ATTR2(NSOpenGLPFASamples, fbconfig->samples); 183 | } 184 | 185 | // NOTE: All NSOpenGLPixelFormats on the relevant cards support sRGB 186 | // frambuffer, so there's no need (and no way) to request it 187 | 188 | ADD_ATTR(0); 189 | 190 | #undef ADD_ATTR 191 | #undef ADD_ATTR2 192 | 193 | window->nsgl.pixelFormat = 194 | [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes]; 195 | if (window->nsgl.pixelFormat == nil) 196 | { 197 | _glfwInputError(GLFW_PLATFORM_ERROR, 198 | "NSOpenGL: Failed to create OpenGL pixel format"); 199 | return GL_FALSE; 200 | } 201 | 202 | NSOpenGLContext* share = NULL; 203 | 204 | if (wndconfig->share) 205 | share = wndconfig->share->nsgl.context; 206 | 207 | window->nsgl.context = 208 | [[NSOpenGLContext alloc] initWithFormat:window->nsgl.pixelFormat 209 | shareContext:share]; 210 | if (window->nsgl.context == nil) 211 | { 212 | _glfwInputError(GLFW_PLATFORM_ERROR, 213 | "NSOpenGL: Failed to create OpenGL context"); 214 | return GL_FALSE; 215 | } 216 | 217 | return GL_TRUE; 218 | } 219 | 220 | // Destroy the OpenGL context 221 | // 222 | void _glfwDestroyContext(_GLFWwindow* window) 223 | { 224 | [window->nsgl.pixelFormat release]; 225 | window->nsgl.pixelFormat = nil; 226 | 227 | [window->nsgl.context release]; 228 | window->nsgl.context = nil; 229 | } 230 | 231 | 232 | ////////////////////////////////////////////////////////////////////////// 233 | ////// GLFW platform API ////// 234 | ////////////////////////////////////////////////////////////////////////// 235 | 236 | void _glfwPlatformMakeContextCurrent(_GLFWwindow* window) 237 | { 238 | if (window) 239 | [window->nsgl.context makeCurrentContext]; 240 | else 241 | [NSOpenGLContext clearCurrentContext]; 242 | 243 | pthread_setspecific(_glfw.nsgl.current, window); 244 | } 245 | 246 | _GLFWwindow* _glfwPlatformGetCurrentContext(void) 247 | { 248 | return (_GLFWwindow*) pthread_getspecific(_glfw.nsgl.current); 249 | } 250 | 251 | void _glfwPlatformSwapBuffers(_GLFWwindow* window) 252 | { 253 | // ARP appears to be unnecessary, but this is future-proof 254 | [window->nsgl.context flushBuffer]; 255 | } 256 | 257 | void _glfwPlatformSwapInterval(int interval) 258 | { 259 | _GLFWwindow* window = _glfwPlatformGetCurrentContext(); 260 | 261 | GLint sync = interval; 262 | [window->nsgl.context setValues:&sync forParameter:NSOpenGLCPSwapInterval]; 263 | } 264 | 265 | int _glfwPlatformExtensionSupported(const char* extension) 266 | { 267 | // There are no NSGL extensions 268 | return GL_FALSE; 269 | } 270 | 271 | GLFWglproc _glfwPlatformGetProcAddress(const char* procname) 272 | { 273 | CFStringRef symbolName = CFStringCreateWithCString(kCFAllocatorDefault, 274 | procname, 275 | kCFStringEncodingASCII); 276 | 277 | GLFWglproc symbol = CFBundleGetFunctionPointerForName(_glfw.nsgl.framework, 278 | symbolName); 279 | 280 | CFRelease(symbolName); 281 | 282 | return symbol; 283 | } 284 | 285 | 286 | ////////////////////////////////////////////////////////////////////////// 287 | ////// GLFW native API ////// 288 | ////////////////////////////////////////////////////////////////////////// 289 | 290 | GLFWAPI id glfwGetNSGLContext(GLFWwindow* handle) 291 | { 292 | _GLFWwindow* window = (_GLFWwindow*) handle; 293 | _GLFW_REQUIRE_INIT_OR_RETURN(nil); 294 | return window->nsgl.context; 295 | } 296 | 297 | -------------------------------------------------------------------------------- /tests/3rdparty/glfw/src/monitor.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW - An OpenGL framework 3 | // Platform: Any 4 | // API version: 3.0 5 | // WWW: http://www.glfw.org/ 6 | //------------------------------------------------------------------------ 7 | // Copyright (c) 2002-2006 Marcus Geelnard 8 | // Copyright (c) 2006-2010 Camilla Berglund 9 | // 10 | // This software is provided 'as-is', without any express or implied 11 | // warranty. In no event will the authors be held liable for any damages 12 | // arising from the use of this software. 13 | // 14 | // Permission is granted to anyone to use this software for any purpose, 15 | // including commercial applications, and to alter it and redistribute it 16 | // freely, subject to the following restrictions: 17 | // 18 | // 1. The origin of this software must not be misrepresented; you must not 19 | // claim that you wrote the original software. If you use this software 20 | // in a product, an acknowledgment in the product documentation would 21 | // be appreciated but is not required. 22 | // 23 | // 2. Altered source versions must be plainly marked as such, and must not 24 | // be misrepresented as being the original software. 25 | // 26 | // 3. This notice may not be removed or altered from any source 27 | // distribution. 28 | // 29 | //======================================================================== 30 | 31 | #include "internal.h" 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | #if defined(_MSC_VER) 38 | #include 39 | #define strdup _strdup 40 | #endif 41 | 42 | 43 | // Lexical comparison function for GLFW video modes, used by qsort 44 | // 45 | static int compareVideoModes(const void* firstPtr, const void* secondPtr) 46 | { 47 | int firstBPP, secondBPP, firstSize, secondSize; 48 | GLFWvidmode* first = (GLFWvidmode*) firstPtr; 49 | GLFWvidmode* second = (GLFWvidmode*) secondPtr; 50 | 51 | // First sort on color bits per pixel 52 | 53 | firstBPP = first->redBits + 54 | first->greenBits + 55 | first->blueBits; 56 | secondBPP = second->redBits + 57 | second->greenBits + 58 | second->blueBits; 59 | 60 | if (firstBPP != secondBPP) 61 | return firstBPP - secondBPP; 62 | 63 | // Then sort on screen area, in pixels 64 | 65 | firstSize = first->width * first->height; 66 | secondSize = second->width * second->height; 67 | 68 | if (firstSize != secondSize) 69 | return firstSize - secondSize; 70 | 71 | // Lastly sort on refresh rate 72 | 73 | return first->refreshRate - second->refreshRate; 74 | } 75 | 76 | // Retrieves the available modes for the specified monitor 77 | // 78 | static int refreshVideoModes(_GLFWmonitor* monitor) 79 | { 80 | int modeCount; 81 | GLFWvidmode* modes; 82 | 83 | if (monitor->modes) 84 | return GL_TRUE; 85 | 86 | modes = _glfwPlatformGetVideoModes(monitor, &modeCount); 87 | if (!modes) 88 | return GL_FALSE; 89 | 90 | qsort(modes, modeCount, sizeof(GLFWvidmode), compareVideoModes); 91 | 92 | free(monitor->modes); 93 | monitor->modes = modes; 94 | monitor->modeCount = modeCount; 95 | 96 | return GL_TRUE; 97 | } 98 | 99 | 100 | ////////////////////////////////////////////////////////////////////////// 101 | ////// GLFW event API ////// 102 | ////////////////////////////////////////////////////////////////////////// 103 | 104 | void _glfwInputMonitorChange(void) 105 | { 106 | int i, j, monitorCount = _glfw.monitorCount; 107 | _GLFWmonitor** monitors = _glfw.monitors; 108 | 109 | _glfw.monitors = _glfwPlatformGetMonitors(&_glfw.monitorCount); 110 | 111 | // Re-use still connected monitor objects 112 | 113 | for (i = 0; i < _glfw.monitorCount; i++) 114 | { 115 | for (j = 0; j < monitorCount; j++) 116 | { 117 | if (_glfwPlatformIsSameMonitor(_glfw.monitors[i], monitors[j])) 118 | { 119 | _glfwDestroyMonitor(_glfw.monitors[i]); 120 | _glfw.monitors[i] = monitors[j]; 121 | break; 122 | } 123 | } 124 | } 125 | 126 | // Find and report disconnected monitors (not in the new list) 127 | 128 | for (i = 0; i < monitorCount; i++) 129 | { 130 | _GLFWwindow* window; 131 | 132 | for (j = 0; j < _glfw.monitorCount; j++) 133 | { 134 | if (monitors[i] == _glfw.monitors[j]) 135 | break; 136 | } 137 | 138 | if (j < _glfw.monitorCount) 139 | continue; 140 | 141 | for (window = _glfw.windowListHead; window; window = window->next) 142 | { 143 | if (window->monitor == monitors[i]) 144 | window->monitor = NULL; 145 | } 146 | 147 | if (_glfw.monitorCallback) 148 | _glfw.monitorCallback((GLFWmonitor*) monitors[i], GLFW_DISCONNECTED); 149 | } 150 | 151 | // Find and report newly connected monitors (not in the old list) 152 | // Re-used monitor objects are then removed from the old list to avoid 153 | // having them destroyed at the end of this function 154 | 155 | for (i = 0; i < _glfw.monitorCount; i++) 156 | { 157 | for (j = 0; j < monitorCount; j++) 158 | { 159 | if (_glfw.monitors[i] == monitors[j]) 160 | { 161 | monitors[j] = NULL; 162 | break; 163 | } 164 | } 165 | 166 | if (j < monitorCount) 167 | continue; 168 | 169 | if (_glfw.monitorCallback) 170 | _glfw.monitorCallback((GLFWmonitor*) _glfw.monitors[i], GLFW_CONNECTED); 171 | } 172 | 173 | _glfwDestroyMonitors(monitors, monitorCount); 174 | } 175 | 176 | 177 | ////////////////////////////////////////////////////////////////////////// 178 | ////// GLFW internal API ////// 179 | ////////////////////////////////////////////////////////////////////////// 180 | 181 | _GLFWmonitor* _glfwCreateMonitor(const char* name, int widthMM, int heightMM) 182 | { 183 | _GLFWmonitor* monitor = (_GLFWmonitor*) calloc(1, sizeof(_GLFWmonitor)); 184 | monitor->name = strdup(name); 185 | monitor->widthMM = widthMM; 186 | monitor->heightMM = heightMM; 187 | 188 | return monitor; 189 | } 190 | 191 | void _glfwDestroyMonitor(_GLFWmonitor* monitor) 192 | { 193 | if (monitor == NULL) 194 | return; 195 | 196 | _glfwFreeGammaRamp(&monitor->originalRamp); 197 | _glfwFreeGammaRamp(&monitor->currentRamp); 198 | 199 | free(monitor->modes); 200 | free(monitor->name); 201 | free(monitor); 202 | } 203 | 204 | void _glfwDestroyMonitors(_GLFWmonitor** monitors, int count) 205 | { 206 | int i; 207 | 208 | for (i = 0; i < count; i++) 209 | _glfwDestroyMonitor(monitors[i]); 210 | 211 | free(monitors); 212 | } 213 | 214 | const GLFWvidmode* _glfwChooseVideoMode(_GLFWmonitor* monitor, 215 | const GLFWvidmode* desired) 216 | { 217 | int i; 218 | unsigned int sizeDiff, leastSizeDiff = UINT_MAX; 219 | unsigned int rateDiff, leastRateDiff = UINT_MAX; 220 | unsigned int colorDiff, leastColorDiff = UINT_MAX; 221 | const GLFWvidmode* current; 222 | const GLFWvidmode* closest = NULL; 223 | 224 | if (!refreshVideoModes(monitor)) 225 | return NULL; 226 | 227 | for (i = 0; i < monitor->modeCount; i++) 228 | { 229 | current = monitor->modes + i; 230 | 231 | colorDiff = abs((current->redBits + current->greenBits + current->blueBits) - 232 | (desired->redBits + desired->greenBits + desired->blueBits)); 233 | 234 | sizeDiff = abs((current->width - desired->width) * 235 | (current->width - desired->width) + 236 | (current->height - desired->height) * 237 | (current->height - desired->height)); 238 | 239 | if (desired->refreshRate) 240 | rateDiff = abs(current->refreshRate - desired->refreshRate); 241 | else 242 | rateDiff = UINT_MAX - current->refreshRate; 243 | 244 | if ((colorDiff < leastColorDiff) || 245 | (colorDiff == leastColorDiff && sizeDiff < leastSizeDiff) || 246 | (colorDiff == leastColorDiff && sizeDiff == leastSizeDiff && rateDiff < leastRateDiff)) 247 | { 248 | closest = current; 249 | leastSizeDiff = sizeDiff; 250 | leastRateDiff = rateDiff; 251 | leastColorDiff = colorDiff; 252 | } 253 | } 254 | 255 | return closest; 256 | } 257 | 258 | int _glfwCompareVideoModes(const GLFWvidmode* first, const GLFWvidmode* second) 259 | { 260 | return compareVideoModes(first, second); 261 | } 262 | 263 | void _glfwSplitBPP(int bpp, int* red, int* green, int* blue) 264 | { 265 | int delta; 266 | 267 | // We assume that by 32 the user really meant 24 268 | if (bpp == 32) 269 | bpp = 24; 270 | 271 | // Convert "bits per pixel" to red, green & blue sizes 272 | 273 | *red = *green = *blue = bpp / 3; 274 | delta = bpp - (*red * 3); 275 | if (delta >= 1) 276 | *green = *green + 1; 277 | 278 | if (delta == 2) 279 | *red = *red + 1; 280 | } 281 | 282 | 283 | ////////////////////////////////////////////////////////////////////////// 284 | ////// GLFW public API ////// 285 | ////////////////////////////////////////////////////////////////////////// 286 | 287 | GLFWAPI GLFWmonitor** glfwGetMonitors(int* count) 288 | { 289 | *count = 0; 290 | 291 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 292 | 293 | *count = _glfw.monitorCount; 294 | return (GLFWmonitor**) _glfw.monitors; 295 | } 296 | 297 | GLFWAPI GLFWmonitor* glfwGetPrimaryMonitor(void) 298 | { 299 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 300 | return (GLFWmonitor*) _glfw.monitors[0]; 301 | } 302 | 303 | GLFWAPI void glfwGetMonitorPos(GLFWmonitor* handle, int* xpos, int* ypos) 304 | { 305 | _GLFWmonitor* monitor = (_GLFWmonitor*) handle; 306 | _GLFW_REQUIRE_INIT(); 307 | _glfwPlatformGetMonitorPos(monitor, xpos, ypos); 308 | } 309 | 310 | GLFWAPI void glfwGetMonitorPhysicalSize(GLFWmonitor* handle, int* width, int* height) 311 | { 312 | _GLFWmonitor* monitor = (_GLFWmonitor*) handle; 313 | 314 | _GLFW_REQUIRE_INIT(); 315 | 316 | if (width) 317 | *width = monitor->widthMM; 318 | if (height) 319 | *height = monitor->heightMM; 320 | } 321 | 322 | GLFWAPI const char* glfwGetMonitorName(GLFWmonitor* handle) 323 | { 324 | _GLFWmonitor* monitor = (_GLFWmonitor*) handle; 325 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 326 | return monitor->name; 327 | } 328 | 329 | GLFWAPI GLFWmonitorfun glfwSetMonitorCallback(GLFWmonitorfun cbfun) 330 | { 331 | GLFWmonitorfun previous; 332 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 333 | 334 | previous = _glfw.monitorCallback; 335 | _glfw.monitorCallback = cbfun; 336 | return previous; 337 | } 338 | 339 | GLFWAPI const GLFWvidmode* glfwGetVideoModes(GLFWmonitor* handle, int* count) 340 | { 341 | _GLFWmonitor* monitor = (_GLFWmonitor*) handle; 342 | 343 | *count = 0; 344 | 345 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 346 | 347 | if (!refreshVideoModes(monitor)) 348 | return NULL; 349 | 350 | *count = monitor->modeCount; 351 | return monitor->modes; 352 | } 353 | 354 | GLFWAPI const GLFWvidmode* glfwGetVideoMode(GLFWmonitor* handle) 355 | { 356 | _GLFWmonitor* monitor = (_GLFWmonitor*) handle; 357 | 358 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 359 | 360 | _glfwPlatformGetVideoMode(monitor, &monitor->currentMode); 361 | return &monitor->currentMode; 362 | } 363 | 364 | --------------------------------------------------------------------------------