81 // your code goes here
92-------------------------------------------------------------------------------
94-------------------------------------------------------------------------------
96Final Platform Layer is released under the following license:
100Copyright (c) 2017-2023 Torsten Spaete
102Permission is hereby granted, free of charge, to any person obtaining a copy
103of this software and associated documentation files (the "Software"), to deal
104in the Software without restriction, including without limitation the rights
105to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
106copies of the Software, and to permit persons to whom the Software is
107furnished to do so, subject to the following conditions:
109The above copyright notice and this permission notice shall be included in all
110copies or substantial portions of the Software.
112THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
113IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
114FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
115AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
116LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
117OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1538#if !defined(__cplusplus) && ((defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || (defined(_MSC_VER) && (_MSC_VER >= 1900)))
1541#elif defined(__cplusplus)
1544# if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || (__cplusplus >= 201103L) || (_MSC_VER >= 1900)
1546# define FPL_IS_CPP11
1549# error "This C/C++ compiler is not supported!"
1556#if defined(__x86_64__) || defined(_M_X64) || defined(__amd64__)
1557# define FPL_ARCH_X64
1558#elif defined(__i386__) || defined(_M_IX86) || defined(__X86__) || defined(_X86_)
1559# define FPL_ARCH_X86
1560#elif defined(__aarch64__) || defined(_M_ARM64)
1561# define FPL_ARCH_ARM64
1562#elif defined(__arm__) || defined(_M_ARM)
1563# define FPL_ARCH_ARM32
1564#elif defined(__powerpc64__) || defined(__ppc64__) || defined(__PPC64__) || defined(_ARCH_PPC64)
1565# define FPL_ARCH_POWERPC64
1566#elif defined(__powerpc__) || defined(__POWERPC__) || defined(__ppc__) || defined(__PPC__) || defined(_ARCH_PPC)
1567# define FPL_ARCH_POWERPC32
1569# error "This architecture is not supported!"
1577# define FPL__M_CPU_64BIT
1579# define FPL__M_CPU_32BIT
1581#elif defined(__GNUC__)
1582# if defined(__LP64__)
1583# define FPL__M_CPU_64BIT
1585# define FPL__M_CPU_32BIT
1588# if (defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 8) || (sizeof(void *) == 8)
1589# define FPL__M_CPU_64BIT
1591# define FPL__M_CPU_32BIT
1595#if defined(FPL__M_CPU_64BIT)
1597# define FPL_CPU_64BIT
1598#elif defined(FPL__M_CPU_32BIT)
1600# define FPL_CPU_32BIT
1608#if defined(__clang__)
1610# define FPL_COMPILER_CLANG
1611#elif defined(__INTEL_COMPILER)
1613# define FPL_COMPILER_INTEL
1614#elif defined(__MINGW32__)
1616# define FPL_COMPILER_MINGW
1617#elif defined(__CC_ARM)
1619# define FPL_COMPILER_ARM
1620#elif defined(__GNUC__)
1622# define FPL_COMPILER_GCC
1623#elif defined(_MSC_VER)
1625# define FPL_COMPILER_MSVC
1628#error "This compiler is not supported!"
1635#if defined(_WIN32) || defined(_WIN64)
1636# define FPL_PLATFORM_WINDOWS
1637# define FPL_PLATFORM_NAME "Windows"
1638#elif defined(__ANDROID__)
1639# define FPL_PLATFORM_ANDROID
1640# define FPL_PLATFORM_NAME "Android"
1641# define FPL_SUBPLATFORM_POSIX
1642# define FPL_SUBPLATFORM_STD_STRINGS
1643# define FPL_SUBPLATFORM_STD_CONSOLE
1644#elif defined(__linux__) || defined(__gnu_linux__)
1645# define FPL_PLATFORM_LINUX
1646# define FPL_PLATFORM_NAME "Linux"
1647# define FPL_SUBPLATFORM_POSIX
1648# define FPL_SUBPLATFORM_X11
1649# define FPL_SUBPLATFORM_STD_STRINGS
1650# define FPL_SUBPLATFORM_STD_CONSOLE
1651#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__bsdi__)
1653# define FPL_PLATFORM_UNIX
1654# define FPL_PLATFORM_NAME "BSD"
1655# define FPL_SUBPLATFORM_BSD
1656# define FPL_SUBPLATFORM_POSIX
1657# define FPL_SUBPLATFORM_X11
1658# define FPL_SUBPLATFORM_STD_STRINGS
1659# define FPL_SUBPLATFORM_STD_CONSOLE
1660#elif defined(unix) || defined(__unix) || defined(__unix__)
1661# define FPL_PLATFORM_UNIX
1662# define FPL_PLATFORM_NAME "Unix"
1663# define FPL_SUBPLATFORM_POSIX
1664# define FPL_SUBPLATFORM_X11
1665# define FPL_SUBPLATFORM_STD_STRINGS
1666# define FPL_SUBPLATFORM_STD_CONSOLE
1668# error "This platform is not supported!"
1672#if defined(FPL_COMPILER_CLANG) || defined(FPL_COMPILER_GCC)
1673#define fpl__m_Asm __asm__
1674#elif defined(FPL_COMPILER_MSVC)
1675#define fpl__m_Asm __asm
1677#define fpl__m_Asm asm
1681#define fplAsm fpl__m_Asm
1684#if defined(FPL_COMPILER_MSVC)
1685# define fpl__MinAlignment 8
1686#elif defined(FPL_COMPILER_GCC) || defined(FPL_COMPILER_CLANG)
1687# if defined(FPL_CPU_64BIT)
1688# define fpl__MinAlignment 8
1690# define fpl__MinAlignment 4
1693# define fpl__MinAlignment 8
1696#define fplMinAlignment fpl__MinAlignment
1699#if defined(FPL_IS_CPP11)
1700#define fpl__m_AlignAs(N) alignas(N)
1701#elif defined(FPL_COMPILER_MSVC)
1702#define fpl__m_AlignAs(N) __declspec(align(N))
1703#elif defined(FPL_COMPILER_GCC) || defined(FPL_COMPILER_CLANG)
1704#define fpl__m_AlignAs(N) __attribute__((aligned(N)))
1706#define fpl__m_AlignAs(N)
1708#define fpl__m_AlignAsAuto(N) fpl__m_AlignAs(((N) < fplMinAlignment ? fplMinAlignment : (N)))
1711#define fplAlignAs(N) fpl__m_AlignAsAuto(N)
1716#if defined(FPL_SUBPLATFORM_POSIX)
1717# if !defined(_XOPEN_SOURCE)
1718# define _XOPEN_SOURCE 600
1720# if !defined(_DEFAULT_SOURCE)
1721# define _DEFAULT_SOURCE 1
1723# if !defined(__STDC_FORMAT_MACROS)
1724# define __STDC_FORMAT_MACROS
1726# if !defined(__STDC_LIMIT_MACROS)
1727# define __STDC_LIMIT_MACROS
1729# if !defined(_LARGEFILE_SOURCE)
1730# define _LARGEFILE_SOURCE
1732# if !defined(_LARGEFILE64_SOURCE)
1733# define _LARGEFILE64_SOURCE
1735# if !defined(_FILE_OFFSET_BITS)
1736# define _FILE_OFFSET_BITS 64
1740#if defined(FPL_PLATFORM_LINUX)
1741# define FPL__INCLUDE_ALLOCA
1743# define FPL__INCLUDE_MALLOC
1747#if defined(FPL_PLATFORM_WINDOWS) && defined(FPL_COMPILER_MINGW)
1748# if !defined(_WIN32_WINNT)
1749# define _WIN32_WINNT 0x0600
1764#define fpl_globalvar static
1766#define fpl_localvar static
1768#define fpl_internal static
1770#define fpl_inline inline
1772#define fpl_internal_inline inline
1774#if defined(FPL_IS_CPP)
1777# define fpl_extern extern
1783#if defined(_WIN32) || defined(__CYGWIN__)
1785# define fpl__m_dllexport __attribute__ ((dllexport))
1786# define fpl__m_dllimport __attribute__ ((dllimport))
1788# define fpl__m_dllexport __declspec(dllexport)
1789# define fpl__m_dllimport __declspec(dllimport)
1791# define fpl__m_dlllocal
1794# define fpl__m_dllimport __attribute__((visibility("default")))
1795# define fpl__m_dllexport __attribute__((visibility("default")))
1796# define fpl__m_dlllocal __attribute__((visibility("hidden")))
1798# define fpl__m_dllimport
1799# define fpl__m_dllexport
1800# define fpl__m_dlllocal
1805#define fpl_dllimport fpl__m_dllimport
1807#define fpl_dllexport fpl__m_dllexport
1809#define fpl_dlllocal fpl__m_dlllocal
1814#if defined(FPL_API_AS_PRIVATE)
1815# define fpl__m_api static
1816#elif defined(FPL_DLLEXPORT)
1817# define fpl__m_api fpl_dllexport
1818#elif defined(FPL_DLLIMPORT)
1819# define fpl__m_api fpl_dllimport
1821# define fpl__m_api fpl_extern
1825#define fpl_api fpl__m_api
1830#if defined(FPL_IS_CPP)
1831# define fpl__m_platform_api extern "C" fpl_api
1832# define fpl__m_common_api extern "C" fpl_api
1834# define fpl__m_platform_api fpl_api
1835# define fpl__m_common_api fpl_api
1839#define fpl_platform_api fpl__m_platform_api
1841#define fpl_common_api fpl__m_common_api
1846#if defined(FPL_COMPILER_MSVC)
1847# define fpl__m_force_inline __forceinline
1848# define fpl__m_no_inline __declspec(noinline)
1849#elif defined(FPL_COMPILER_GCC) || defined(FPL_COMPILER_CLANG)
1850# define fpl__m_force_inline __attribute__((__always_inline__)) inline
1851# define fpl__m_no_inline __attribute__((noinline))
1853# define fpl__m_force_inline inline
1854# define fpl__m_no_inline
1858#define fpl_force_inline fpl__m_force_inline
1860#define fpl_no_inline fpl__m_no_inline
1867#if defined(FPL_NO_CRT)
1868# if defined(FPL_SUBPLATFORM_STD_CONSOLE)
1869# undef FPL_SUBPLATFORM_STD_CONSOLE
1871# if defined(FPL_SUBPLATFORM_STD_STRINGS)
1872# undef FPL_SUBPLATFORM_STD_STRINGS
1874# if !defined(FPL_USERFUNC_vsnprintf)
1875# error "You need to provide a replacement for vsnprintf() by defining FPL_USERFUNC_vsnprintf!"
1884#if defined(FPL_APPTYPE_CONSOLE) && defined(FPL_APPTYPE_WINDOW)
1885# error "Its now allowed to define both FPL_APPTYPE_CONSOLE and FPL_APPTYPE_WINDOW!"
1887#if defined(FPL_NO_CRT)
1888# if !defined(FPL_APPTYPE_CONSOLE) && !defined(FPL_APPTYPE_WINDOW)
1889# error "In 'No-CRT' mode you need to define either FPL_APPTYPE_CONSOLE or FPL_APPTYPE_WINDOW manually!"
1891#elif !defined(FPL_NO_APPTYPE) && !(defined(FPL_APPTYPE_CONSOLE) || defined(FPL_APPTYPE_WINDOW))
1892# if !defined(FPL_NO_WINDOW)
1894# define FPL_APPTYPE_WINDOW
1897# define FPL_APPTYPE_CONSOLE
1904#if defined(FPL_IMPLEMENTATION) && !defined(FPL_NO_ENTRYPOINT)
1905# define FPL_ENTRYPOINT
1911#if defined(FPL_DEBUG)
1912# define FPL__ENABLE_DEBUG
1913#elif defined(FPL_RELEASE)
1914# define FPL__ENABLE_RELEASE
1920#if defined(FPL_COMPILER_MSVC)
1922# if !defined(FPL__ENABLE_DEBUG) && !defined(FPL__ENABLE_RELEASE)
1923# if defined(_DEBUG) || (!defined(NDEBUG))
1924# define FPL__ENABLE_DEBUG
1926# define FPL__ENABLE_RELEASE
1931# define FPL__M_FUNCTION_NAME __FUNCTION__
1934# if defined(FPL_APPTYPE_WINDOW)
1935# pragma comment(linker, "/SUBSYSTEM:WINDOWS")
1936# elif defined(FPL_APPTYPE_CONSOLE)
1937# pragma comment(linker, "/SUBSYSTEM:CONSOLE")
1941# pragma comment(lib, "kernel32.lib")
1944# define FPL__M_FUNCTION_NAME __FUNCTION__
1948#if !defined(FPL__ENABLE_DEBUG) && !defined(FPL__ENABLE_RELEASE)
1949# define FPL__ENABLE_DEBUG
1953#if defined(__INTELLISENSE__) || defined(__JETBRAINS_IDE__)
1954# define FPL_IS_IDE 1
1956# define FPL_IS_IDE 0
1960#define FPL_FUNCTION_NAME FPL__M_FUNCTION_NAME
1969#if defined(__AVX512F__)
1970# define FPL__COMPILED_X86_CPU_INSTR_SET 9
1971#elif defined(__AVX2__)
1972# define FPL__COMPILED_X86_CPU_INSTR_SET 8
1973#elif defined(__AVX__)
1974# define FPL__COMPILED_X86_CPU_INSTR_SET 7
1975#elif defined(__SSE4_2__)
1976# define FPL__COMPILED_X86_CPU_INSTR_SET 6
1977#elif defined(__SSE4_1__)
1978# define FPL__COMPILED_X86_CPU_INSTR_SET 5
1979#elif defined(__SSSE3__)
1980# define FPL__COMPILED_X86_CPU_INSTR_SET 4
1981#elif defined(__SSE3__)
1982# define FPL__COMPILED_X86_CPU_INSTR_SET 3
1983#elif defined(__SSE2__) || (_M_IX86_FP >= 2)
1984# define FPL__COMPILED_X86_CPU_INSTR_SET 2
1985#elif defined(__SSE__) || (_M_IX86_FP >= 1)
1986# define FPL__COMPILED_X86_CPU_INSTR_SET 1
1987#elif defined(_M_IX86_FP)
1988# define FPL__COMPILED_X86_CPU_INSTR_SET _M_IX86_FP
1990# define FPL__COMPILED_X86_CPU_INSTR_SET 0
1996#if !defined(FPL_NO_ASSERTIONS)
1997# if !defined(FPL_FORCE_ASSERTIONS)
1998# if defined(FPL__ENABLE_DEBUG)
1999# define FPL__ENABLE_ASSERTIONS
2002# define FPL__ENABLE_ASSERTIONS
2005#if defined(FPL__ENABLE_ASSERTIONS)
2006# if !defined(FPL_NO_C_ASSERT) && !defined(FPL_NO_CRT)
2007# define FPL__ENABLE_C_ASSERT
2014#if defined(__has_include)
2015# define fpl__m_HasInclude(inc) __has_include(inc)
2017# define fpl__m_HasInclude(inc) (1)
2020#define fplHasInclude(inc) fpl__m_HasInclude(inc)
2025#if !defined(FPL_NO_WINDOW) && !defined(FPL_APPTYPE_CONSOLE)
2026# define FPL__SUPPORT_WINDOW
2032#if !defined(FPL_NO_VIDEO)
2033# define FPL__SUPPORT_VIDEO
2035#if defined(FPL__SUPPORT_VIDEO)
2036# if !defined(FPL_NO_VIDEO_OPENGL)
2037# define FPL__SUPPORT_VIDEO_OPENGL
2039# if !defined(FPL_NO_VIDEO_VULKAN)
2040# define FPL__SUPPORT_VIDEO_VULKAN
2042# if !defined(FPL_NO_VIDEO_SOFTWARE)
2043# define FPL__SUPPORT_VIDEO_SOFTWARE
2050#if !defined(FPL_NO_AUDIO)
2052# define FPL__SUPPORT_AUDIO
2054#if defined(FPL__SUPPORT_AUDIO)
2055# if !defined(FPL_NO_AUDIO_DIRECTSOUND) && defined(FPL_PLATFORM_WINDOWS)
2056# define FPL__SUPPORT_AUDIO_DIRECTSOUND
2058# if !defined(FPL_NO_AUDIO_ALSA) && defined(FPL_PLATFORM_LINUX)
2059# if fplHasInclude(<alsa/asoundlib.h>)
2060# define FPL__SUPPORT_AUDIO_ALSA
2062# warning "FPL-Warning: ALSA audio development library is missing. Please install 'libasound2-dev' and try again!"
2070#if !defined(FPL__SUPPORT_WINDOW)
2071# if defined(FPL_SUBPLATFORM_X11)
2072# undef FPL_SUBPLATFORM_X11
2075# if defined(FPL__SUPPORT_VIDEO)
2076# undef FPL__SUPPORT_VIDEO
2078# if defined(FPL__SUPPORT_VIDEO_OPENGL)
2079# undef FPL__SUPPORT_VIDEO_OPENGL
2081# if defined(FPL__SUPPORT_VIDEO_VULKAN)
2082# undef FPL__SUPPORT_VIDEO_VULKAN
2084# if defined(FPL__SUPPORT_VIDEO_SOFTWARE)
2085# undef FPL__SUPPORT_VIDEO_SOFTWARE
2092#if defined(FPL__SUPPORT_WINDOW)
2093# define FPL__ENABLE_WINDOW
2096#if defined(FPL__SUPPORT_VIDEO)
2097# define FPL__ENABLE_VIDEO
2098# if defined(FPL__SUPPORT_VIDEO_OPENGL)
2099# define FPL__ENABLE_VIDEO_OPENGL
2101# if defined(FPL__SUPPORT_VIDEO_VULKAN)
2102# define FPL__ENABLE_VIDEO_VULKAN
2104# if defined(FPL__SUPPORT_VIDEO_SOFTWARE)
2105# define FPL__ENABLE_VIDEO_SOFTWARE
2109#if defined(FPL__SUPPORT_AUDIO)
2110# define FPL__ENABLE_AUDIO
2111# if defined(FPL__SUPPORT_AUDIO_DIRECTSOUND)
2112# define FPL__ENABLE_AUDIO_DIRECTSOUND
2114# if defined(FPL__SUPPORT_AUDIO_ALSA)
2115# define FPL__ENABLE_AUDIO_ALSA
2119#if defined(FPL_LOGGING)
2120# define FPL__ENABLE_LOGGING
2121# if defined(FPL_LOG_MULTIPLE_WRITERS)
2122# define FPL__ENABLE_LOG_MULTIPLE_WRITERS
2136#if defined(FPL__ENABLE_ASSERTIONS)
2137# if defined(FPL__ENABLE_C_ASSERT) && !defined(FPL_FORCE_ASSERTIONS)
2138# define FPL__INCLUDE_ASSERT
2139# define fpl__m_Assert(exp) assert(exp)
2140# if defined(__cplusplus)
2141# define fpl__m_StaticAssert(exp) static_assert(exp, "fpl_static_assert")
2144# define fpl__m_Assert(exp) if(!(exp)) {*(int *)0 = 0;}
2146# if !defined(fpl__m_StaticAssert)
2147# define FPL__M_STATICASSERT_0(exp, line, counter) \
2148 int fpl__ct_assert_##line_##counter(int ct_assert_failed[(exp)?1:-1])
2149# define fpl__m_StaticAssert(exp) \
2150 FPL__M_STATICASSERT_0(exp, __LINE__, __COUNTER__)
2153# define fpl__m_Assert(exp)
2154# define fpl__m_StaticAssert(exp)
2158#define fplAssert(exp) fpl__m_Assert(exp)
2160#define fplStaticAssert(exp) fpl__m_StaticAssert(exp)
2162#define fplAlwaysAssert(exp) if(!(exp)) {*(int *)0 = 0;}
2164#define fplAssertPtr(ptr) fpl__m_Assert((ptr) != fpl_null)
2170#if defined(__has_builtin)
2171# if __has_builtin(__builtin_debugtrap)
2172# define fpl__m_DebugBreak() __builtin_debugtrap()
2173# elif __has_builtin(__debugbreak)
2174# define fpl__m_DebugBreak() __debugbreak()
2177#if !defined(fpl__m_DebugBreak)
2178# if defined(FPL_COMPILER_MSVC) || defined(FPL_COMPILER_INTEL)
2179# define fpl__m_DebugBreak() __debugbreak()
2180# elif defined(FPL_COMPILER_ARM)
2181# define fpl__m_DebugBreak() __breakpoint(42)
2182# elif defined(FPL_ARCH_X86) || defined(FPL_ARCH_X64)
2184# elif defined(__thumb__)
2186# elif defined(FPL_ARCH_ARM64)
2188# elif defined(FPL_ARCH_ARM32)
2190# elif defined(FPL_COMPILER_GCC)
2191# define fpl__m_DebugBreak() __builtin_trap()
2193# define FPL__INCLUDE_SIGNAL
2194# if defined(SIGTRAP)
2195# define fpl__m_DebugBreak() raise(SIGTRAP)
2197# define fpl__m_DebugBreak() raise(SIGABRT)
2203#define fplDebugBreak() fpl__m_DebugBreak()
2217#if !defined(FPL_NO_MEMORY_MACROS) || defined(FPL_FORCE_MEMORY_MACROS)
2218# define FPL__ENABLE_MEMORY_MACROS
2231#if defined(FPL__INCLUDE_ASSERT)
2234#if defined(FPL__INCLUDE_SIGNAL)
2237#if defined(FPL__INCLUDE_MALLOC)
2240#if defined(FPL__INCLUDE_ALLOCA)
2245#if !defined(UINT32_MAX)
2247# define UINT32_MAX ((uint32_t)-1)
2251#if defined(FPL_IS_CPP11)
2252# define fpl__m_null nullptr
2254# define fpl__m_null NULL
2256# define fpl__m_null 0
2259#define fpl_null fpl__m_null
2268#if defined(FPL_CPU_64BIT)
2271#elif defined(FPL_CPU_32BIT)
2288#define FPL_NOT_IMPLEMENTED {*(int *)0 = 0xBAD;}
2290#if defined(FPL_IS_C99)
2291# define fpl__m_ZeroInit {0}
2292# define fpl__m_StructSet(ptr, type, value) *(ptr) = (type)value
2293# define fpl__m_StructInit(type, ...) (type){__VA_ARGS__}
2295# define fpl__m_ZeroInit {}
2296# define fpl__m_StructSet(ptr, type, value) *(ptr) = value
2297# define fpl__m_StructInit(type, ...) {__VA_ARGS__}
2301#define fplZeroInit fpl__m_ZeroInit
2303#define fplStructSet fpl__m_StructSet
2305#define fplStructInit fpl__m_StructInit
2308#define fplGetAlignmentOffset(value, alignment) ( (((alignment) > 1) && (((value) & ((alignment) - 1)) != 0)) ? ((alignment) - ((value) & (alignment - 1))) : 0)
2310#define fplGetAlignedSize(size, alignment) (((size) > 0 && (alignment) > 0) ? ((size) + fplGetAlignmentOffset(size, alignment)) : (size))
2312#define fplIsAligned(ptr, alignment) (((uintptr_t)(const void *)(ptr)) % (alignment) == 0)
2314#define fplIsPowerOfTwo(value) (((value) != 0) && (((value) & (~(value) + 1)) == (value)))
2316#define fplIsBigEndian() (*(uint16_t *)"\0\xff" < 0x100)
2318#define fplIsLittleEndian() (!fplIsBigEndian())
2320#define fplIsBitSet(value, bit) (((value) >> (bit)) & 0x1)
2323#define fplKiloBytes(value) (((value) * 1024ull))
2325#define fplMegaBytes(value) ((fplKiloBytes(value) * 1024ull))
2327#define fplGigaBytes(value) ((fplMegaBytes(value) * 1024ull))
2329#define fplTeraBytes(value) ((fplGigaBytes(value) * 1024ull))
2332#define fplClearStruct(ptr) fplMemoryClear((void *)(ptr), sizeof(*(ptr)))
2334#define fplCopyStruct(src, dst) fplMemoryCopy(src, sizeof(*(src)), dst);
2337#if defined(FPL_COMPILER_MSVC) && !defined(FPL_NO_CRT)
2338# define fpl__m_ArrayCount(arr) _countof(arr)
2339#elif defined(ARRAY_SIZE)
2340# define fpl__m_ArrayCount(arr) ARRAY_SIZE(arr)
2343# define FPL__NO_ARRAYCOUNT_VALIDATION
2344# define fpl__m_ArrayCount(arr) (sizeof(arr) / sizeof((arr)[0]))
2347#define fplArrayCount(arr) fpl__m_ArrayCount(arr)
2350#define fplOffsetOf(type, field) ((size_t)(&(((type*)(0))->field)))
2353#define fplMin(a, b) ((a) < (b) ? (a) : (b))
2356#define fplMax(a, b) ((a) > (b) ? (a) : (b))
2358#if defined(FPL_PLATFORM_WINDOWS)
2359# define fpl__m_StackAllocate(size) _alloca(size)
2361# define fpl__m_StackAllocate(size) alloca(size)
2365#define fplStackAllocate(size) fpl__m_StackAllocate(size)
2369#if defined(FPL_IS_CPP)
2370# define FPL__M_ENUM_AS_FLAGS_OPERATORS(etype) \
2371 inline etype operator | (etype a, etype b) { \
2372 return static_cast<etype>(static_cast<int>(a) | static_cast<int>(b)); \
2374 inline etype& operator |= (etype &a, etype b) { \
2377 inline etype operator & (etype a, etype b) { \
2378 return static_cast<etype>(static_cast<int>(a) & static_cast<int>(b)); \
2380 inline etype& operator &= (etype &a, etype b) { \
2383 inline etype operator ~ (etype a) { \
2384 return static_cast<etype>(~static_cast<int>(a)); \
2386 inline etype operator ^ (etype a, etype b) { \
2387 return static_cast<etype>(static_cast<int>(a) ^ static_cast<int>(b)); \
2389 inline etype& operator ^= (etype &a, etype b) { \
2393# define FPL__M_ENUM_AS_FLAGS_OPERATORS(etype)
2397#define FPL_ENUM_AS_FLAGS_OPERATORS(type) FPL__M_ENUM_AS_FLAGS_OPERATORS(type)
2404#if !defined(FPL_NO_PLATFORM_INCLUDES) && !defined(FPL__HAS_PLATFORM_INCLUDES)
2405# define FPL__HAS_PLATFORM_INCLUDES
2407# if defined(FPL_PLATFORM_WINDOWS)
2409# if !defined(NOMINMAX)
2413# if !defined(WIN32_LEAN_AND_MEAN)
2414# define WIN32_LEAN_AND_MEAN 1
2418# include <windows.h>
2419# if _WIN32_WINNT < 0x0600
2420# error "Windows Vista or higher required!"
2424# if defined(FPL_SUBPLATFORM_POSIX)
2425# include <pthread.h>
2427# include <semaphore.h>
2431# if defined(FPL_SUBPLATFORM_X11)
2433# include <X11/Xlib.h>
2434# include <X11/Xutil.h>
2435# include <X11/Xatom.h>
2443#if !defined(FPL__HAS_PLATFORM_INCLUDES) || defined(FPL_OPAQUE_HANDLES)
2445# if defined(FPL_PLATFORM_WINDOWS)
2448typedef uint64_t fpl__Win32Guid[4];
2450typedef void *fpl__Win32Handle;
2452typedef fpl__Win32Handle fpl__Win32InstanceHandle;
2454typedef fpl__Win32Handle fpl__Win32LibraryHandle;
2456typedef fpl__Win32Handle fpl__Win32FileHandle;
2458typedef fpl__Win32Handle fpl__Win32ThreadHandle;
2460typedef uint64_t fpl__Win32MutexHandle[16];
2462typedef fpl__Win32Handle fpl__Win32SignalHandle;
2464typedef void *fpl__Win32ConditionVariable;
2466typedef fpl__Win32Handle fpl__Win32SemaphoreHandle;
2468typedef fpl__Win32Handle fpl__Win32WindowHandle;
2470typedef fpl__Win32Handle fpl__Win32DeviceContext;
2472typedef fpl__Win32Handle fpl__Win32RenderingContext;
2474typedef union fpl__Win32LargeInteger {
2483} fpl__Win32LargeInteger;
2487# if defined(FPL_SUBPLATFORM_POSIX)
2490typedef void *fpl__POSIXLibraryHandle;
2492typedef int fpl__POSIXFileHandle;
2494typedef void *fpl__POSIXDirHandle;
2496typedef uint64_t fpl__POSIXThreadHandle;
2498typedef uint64_t fpl__POSIXMutexHandle[16];
2500typedef uint64_t fpl__POSIXSemaphoreHandle[8];
2502typedef uint64_t fpl__POSIXConditionVariable[16];
2506# if defined(FPL_SUBPLATFORM_X11)
2509typedef void *fpl__X11Display;
2511typedef int fpl__X11Window;
2513typedef void *fpl__X11Visual;
2515typedef void *fpl__X11GC;
2517typedef void *fpl__X11Image;
2519typedef void *fpl__GLXContext;
2523# if defined(FPL_PLATFORM_LINUX)
2526typedef int fpl__LinuxSignalHandle;
2532# if defined(FPL_PLATFORM_WINDOWS)
2535typedef GUID fpl__Win32Guid;
2537typedef HANDLE fpl__Win32Handle;
2539typedef HINSTANCE fpl__Win32InstanceHandle;
2541typedef HMODULE fpl__Win32LibraryHandle;
2543typedef HANDLE fpl__Win32ThreadHandle;
2545typedef HANDLE fpl__Win32FileHandle;
2547typedef CRITICAL_SECTION fpl__Win32MutexHandle;
2549typedef HANDLE fpl__Win32SignalHandle;
2551typedef CONDITION_VARIABLE fpl__Win32ConditionVariable;
2553typedef HANDLE fpl__Win32SemaphoreHandle;
2555typedef HWND fpl__Win32WindowHandle;
2557typedef HDC fpl__Win32DeviceContext;
2559typedef HGLRC fpl__Win32RenderingContext;
2561typedef LARGE_INTEGER fpl__Win32LargeInteger;
2565# if defined(FPL_SUBPLATFORM_POSIX)
2568typedef void *fpl__POSIXLibraryHandle;
2570typedef int fpl__POSIXFileHandle;
2572typedef DIR *fpl__POSIXDirHandle;
2574typedef pthread_t fpl__POSIXThreadHandle;
2576typedef pthread_mutex_t fpl__POSIXMutexHandle;
2578typedef sem_t fpl__POSIXSemaphoreHandle;
2580typedef pthread_cond_t fpl__POSIXConditionVariable;
2584# if defined(FPL_SUBPLATFORM_X11)
2587typedef Display *fpl__X11Display;
2589typedef Window fpl__X11Window;
2591typedef Visual *fpl__X11Visual;
2593typedef GC fpl__X11GC;
2595typedef XImage *fpl__X11Image;
2597typedef void *fpl__GLXContext;
2602# if defined(FPL_PLATFORM_LINUX)
2605typedef int fpl__LinuxSignalHandle;
2621#if defined(FPL_PLATFORM_WINDOWS)
2622# if defined(MAX_PATH)
2623# define FPL__M_MAX_FILENAME_LENGTH (MAX_PATH)
2624# define FPL__M_MAX_PATH_LENGTH (MAX_PATH * 2)
2626# define FPL__M_MAX_FILENAME_LENGTH (260)
2627# define FPL__M_MAX_PATH_LENGTH (260 * 2)
2629# define FPL__M_PATH_SEPARATOR '\\'
2630# define FPL__M_FILE_EXT_SEPARATOR '.'
2632# define FPL__M_MAX_FILENAME_LENGTH (512)
2633# define FPL__M_MAX_PATH_LENGTH (2048)
2634# define FPL__M_PATH_SEPARATOR '/'
2635# define FPL__M_FILE_EXT_SEPARATOR '.'
2639#define FPL_MAX_FILENAME_LENGTH FPL__M_MAX_FILENAME_LENGTH
2641#define FPL_MAX_PATH_LENGTH FPL__M_MAX_PATH_LENGTH
2643#define FPL_PATH_SEPARATOR FPL__M_PATH_SEPARATOR
2645#define FPL_FILE_EXT_SEPARATOR FPL__M_FILE_EXT_SEPARATOR
2647#define FPL_MAX_NAME_LENGTH (256)
2649#define FPL_MAX_BUFFER_LENGTH (2048)
3568#if defined(FPL__ENABLE_VIDEO_OPENGL)
3596#if defined(FPL__ENABLE_VIDEO_VULKAN)
3599typedef void (
fplVulkanValidationLayerCallback)(
void *userData,
const char *message,
const uint32_t messageSeverity,
const uint32_t messageType,
const void *debugUtilsMessengerCallbackData);
3658#if defined(FPL__ENABLE_VIDEO_OPENGL)
3662#if defined(FPL__ENABLE_VIDEO_VULKAN)
3800#if defined(FPL__ENABLE_AUDIO_DIRECTSOUND)
3802 fpl__Win32Guid dshow;
3804#if defined(FPL__ENABLE_AUDIO_ALSA)
3820#if defined(FPL__ENABLE_AUDIO_ALSA)
3822typedef struct fplAlsaAudioSettings {
3825} fplAlsaAudioSettings;
3830#if defined(FPL__ENABLE_AUDIO_ALSA)
3832 fplAlsaAudioSettings alsa;
4196#if defined(FPL__ENABLE_LOGGING)
4247#if defined(FPL__ENABLE_LOG_MULTIPLE_WRITERS)
4271 fplLogLevel maxLevel;
4357#if defined(FPL_PLATFORM_WINDOWS)
4359 fpl__Win32LibraryHandle win32LibraryHandle;
4360#elif defined(FPL_SUBPLATFORM_POSIX)
4362 fpl__POSIXLibraryHandle posixLibraryHandle;
4478#if defined(FPL_PLATFORM_WINDOWS)
4482 fpl__Win32LargeInteger qpc;
4486#elif defined(FPL_SUBPLATFORM_POSIX)
4492 int64_t nanoSeconds;
4502#define FPL_TIMEOUT_INFINITE UINT32_MAX
4591#if defined(FPL_PLATFORM_WINDOWS)
4593 fpl__Win32ThreadHandle win32ThreadHandle;
4594#elif defined(FPL_SUBPLATFORM_POSIX)
4596 fpl__POSIXThreadHandle posixThread;
4628#if defined(FPL_PLATFORM_WINDOWS)
4629typedef struct fpl__Win32InternalSemaphore {
4631 fpl__Win32SemaphoreHandle handle;
4633 volatile int32_t value;
4634} fpl__Win32InternalSemaphore;
4639#if defined(FPL_PLATFORM_WINDOWS)
4641 fpl__Win32InternalSemaphore win32;
4642#elif defined(FPL_SUBPLATFORM_POSIX)
4644 fpl__POSIXSemaphoreHandle posixHandle;
4658#if defined(FPL_PLATFORM_WINDOWS)
4660 fpl__Win32MutexHandle win32CriticalSection;
4661#elif defined(FPL_SUBPLATFORM_POSIX)
4663 fpl__POSIXMutexHandle posixMutex;
4677#if defined(FPL_PLATFORM_WINDOWS)
4679 fpl__Win32SignalHandle win32EventHandle;
4680#elif defined(FPL_PLATFORM_LINUX)
4682 fpl__LinuxSignalHandle linuxEventHandle;
4704#if defined(FPL_PLATFORM_WINDOWS)
4706 fpl__Win32ConditionVariable win32Condition;
4707#elif defined(FPL_SUBPLATFORM_POSIX)
4709 fpl__POSIXConditionVariable posixCondition;
5178#if defined(FPL_PLATFORM_WINDOWS)
5180 fpl__Win32FileHandle win32FileHandle;
5181#elif defined(FPL_SUBPLATFORM_POSIX)
5183 fpl__POSIXFileHandle posixFileHandle;
5277#if defined(FPL_PLATFORM_WINDOWS)
5279 fpl__Win32FileHandle win32FileHandle;
5280#elif defined(FPL_SUBPLATFORM_POSIX)
5282 fpl__POSIXDirHandle posixDirHandle;
5679#if defined(FPL__ENABLE_WINDOW)
5694 fplKey_Backspace = 0x08,
5699 fplKey_Clear = 0x0C,
5700 fplKey_Return = 0x0D,
5704 fplKey_Shift = 0x10,
5705 fplKey_Control = 0x11,
5707 fplKey_Pause = 0x13,
5708 fplKey_CapsLock = 0x14,
5715 fplKey_Escape = 0x1B,
5719 fplKey_Space = 0x20,
5720 fplKey_PageUp = 0x21,
5721 fplKey_PageDown = 0x22,
5726 fplKey_Right = 0x27,
5728 fplKey_Select = 0x29,
5729 fplKey_Print = 0x2A,
5730 fplKey_Execute = 0x2B,
5731 fplKey_Snapshot = 0x2C,
5732 fplKey_Insert = 0x2D,
5733 fplKey_Delete = 0x2E,
5776 fplKey_LeftSuper = 0x5B,
5777 fplKey_RightSuper = 0x5C,
5782 fplKey_Sleep = 0x5F,
5783 fplKey_NumPad0 = 0x60,
5784 fplKey_NumPad1 = 0x61,
5785 fplKey_NumPad2 = 0x62,
5786 fplKey_NumPad3 = 0x63,
5787 fplKey_NumPad4 = 0x64,
5788 fplKey_NumPad5 = 0x65,
5789 fplKey_NumPad6 = 0x66,
5790 fplKey_NumPad7 = 0x67,
5791 fplKey_NumPad8 = 0x68,
5792 fplKey_NumPad9 = 0x69,
5793 fplKey_Multiply = 0x6A,
5795 fplKey_Separator = 0x6C,
5796 fplKey_Substract = 0x6D,
5797 fplKey_Decimal = 0x6E,
5798 fplKey_Divide = 0x6F,
5826 fplKey_NumLock = 0x90,
5827 fplKey_Scroll = 0x91,
5832 fplKey_LeftShift = 0xA0,
5833 fplKey_RightShift = 0xA1,
5834 fplKey_LeftControl = 0xA2,
5835 fplKey_RightControl = 0xA3,
5836 fplKey_LeftAlt = 0xA4,
5837 fplKey_RightAlt = 0xA5,
5841 fplKey_VolumeMute = 0xAD,
5842 fplKey_VolumeDown = 0xAE,
5843 fplKey_VolumeUp = 0xAF,
5844 fplKey_MediaNextTrack = 0xB0,
5845 fplKey_MediaPrevTrack = 0xB1,
5846 fplKey_MediaStop = 0xB2,
5847 fplKey_MediaPlayPause = 0xB3,
6228#define FPL_MAX_KEYBOARD_STATE_COUNT 256
6241#define FPL_MAX_GAMEPAD_STATE_COUNT 4
6564#if defined(FPL__ENABLE_VIDEO)
6594 fplVideoRect result = { left, top, (right - left) + 1, (bottom - top) + 1 };
6616#if defined(FPL__ENABLE_VIDEO_VULKAN)
6626#if defined(FPL__ENABLE_VIDEO_OPENGL)
6634#if defined(FPL_PLATFORM_WINDOWS)
6636typedef struct fplVideoWindowWin32 {
6638 fpl__Win32WindowHandle windowHandle;
6640 fpl__Win32DeviceContext deviceContext;
6641} fplVideoWindowWin32;
6644#if defined(FPL_SUBPLATFORM_X11)
6646typedef struct fplVideoWindowX11 {
6648 fpl__X11Window window;
6650 fpl__X11Display display;
6652 fpl__X11Visual visual;
6660#if defined(FPL_PLATFORM_WINDOWS)
6661 fplVideoWindowWin32 win32;
6662#elif defined(FPL_SUBPLATFORM_X11)
6663 fplVideoWindowX11 x11;
6674#if defined(FPL__ENABLE_VIDEO_VULKAN)
6679#if defined(FPL__ENABLE_VIDEO_OPENGL)
6688#if defined(FPL__ENABLE_VIDEO_VULKAN)
6701#if defined(FPL__ENABLE_VIDEO_VULKAN)
6763#if defined(FPL__ENABLE_AUDIO)
6960#if defined(FPL_PLATFORM_WINDOWS)
6961# if defined(FPL_ENTRYPOINT)
6963fpl_main int main(
int argc,
char **args);
7034#if (defined(FPL_IMPLEMENTATION) || FPL_IS_IDE) && !defined(FPL__IMPLEMENTED)
7035#define FPL__IMPLEMENTED
7042#if !defined(FPL__COMPILER_CONFIG_DEFINED)
7043#define FPL__COMPILER_CONFIG_DEFINED
7048#if defined(FPL_COMPILER_MSVC)
7051# pragma warning( push )
7054# pragma warning( disable : 4577 )
7056# pragma warning( disable : 4065 )
7058# pragma warning( disable : 4127 )
7060# pragma warning( disable : 4100 )
7062# pragma warning( disable : 4201 )
7064# pragma warning( disable : 4189 )
7066# pragma warning( disable : 4204 )
7068#elif defined(FPL_COMPILER_GCC)
7071# pragma GCC diagnostic push
7073# pragma GCC diagnostic ignored "-Wunused-variable"
7075# pragma GCC diagnostic ignored "-Wunused-function"
7077#elif defined(FPL_COMPILER_CLANG)
7080# pragma clang diagnostic push
7083# pragma clang diagnostic ignored "-Wunused-variable"
7085# pragma clang diagnostic ignored "-Wunused-function"
7096#if !defined(FPL__PLATFORM_INCLUDES_DEFINED)
7097#define FPL__PLATFORM_INCLUDES_DEFINED
7099#if !defined(FPL__HAS_PLATFORM_INCLUDES)
7100# define FPL__HAS_PLATFORM_INCLUDES
7102# if defined(FPL_PLATFORM_WINDOWS)
7104# if !defined(NOMINMAX)
7108# if !defined(WIN32_LEAN_AND_MEAN)
7109# define WIN32_LEAN_AND_MEAN 1
7113# include <windows.h>
7114# if _WIN32_WINNT < 0x0600
7115# error "Windows Vista or higher required!"
7119# if defined(FPL_SUBPLATFORM_POSIX)
7120# include <pthread.h>
7122# include <semaphore.h>
7126# if defined(FPL_SUBPLATFORM_X11)
7128# include <X11/Xlib.h>
7129# include <X11/Xutil.h>
7130# include <X11/Xatom.h>
7138#if defined(FPL_PLATFORM_WINDOWS)
7143fplStaticAssert(
sizeof(fpl__Win32MutexHandle) >=
sizeof(CRITICAL_SECTION));
7145fplStaticAssert(
sizeof(fpl__Win32ConditionVariable) >=
sizeof(CONDITION_VARIABLE));
7146#elif defined(FPL_SUBPLATFORM_POSIX)
7151fplStaticAssert(
sizeof(fpl__POSIXMutexHandle) >=
sizeof(pthread_mutex_t));
7153fplStaticAssert(
sizeof(fpl__POSIXConditionVariable) >=
sizeof(pthread_cond_t));
7155#if defined(FPL_PLATFORM_LINUX)
7162#if defined(FPL_COMPILER_MSVC)
7164#elif defined(FPL_COMPILER_GCC) || defined(FPL_COMPILER_CLANG)
7165# if defined(FPL_ARCH_X86) || defined(FPL_ARCH_X64)
7171#if !defined(FPL_NO_CRT)
7184#if !defined(FPL__INTERNAL_TOP_DEFINED)
7185#define FPL__INTERNAL_TOP_DEFINED
7188#define FPL__MODULE_CORE "Core"
7189#define FPL__MODULE_FILES "Files"
7190#define FPL__MODULE_THREADING "Threading"
7191#define FPL__MODULE_MEMORY "Memory"
7192#define FPL__MODULE_WINDOW "Window"
7193#define FPL__MODULE_LIBRARIES "Libraries"
7194#define FPL__MODULE_OS "OS"
7195#define FPL__MODULE_HARDWARE "Hardware"
7196#define FPL__MODULE_STRINGS "Strings"
7197#define FPL__MODULE_PATHS "Paths"
7198#define FPL__MODULE_ARGS "Arguments"
7200#define FPL__MODULE_AUDIO "Audio"
7201#define FPL__MODULE_AUDIO_DIRECTSOUND "DirectSound"
7202#define FPL__MODULE_AUDIO_ALSA "ALSA"
7204#define FPL__MODULE_VIDEO "Video"
7205#define FPL__MODULE_VIDEO_OPENGL "OpenGL"
7206#define FPL__MODULE_VIDEO_VULKAN "Vulkan"
7207#define FPL__MODULE_VIDEO_SOFTWARE "Software"
7209#define FPL__MODULE_WIN32 "Win32"
7210#define FPL__MODULE_XINPUT "XInput"
7212#define FPL__MODULE_LINUX "Linux"
7213#define FPL__MODULE_UNIX "Unix"
7214#define FPL__MODULE_POSIX "POSIX"
7215#define FPL__MODULE_PTHREAD "pthread"
7216#define FPL__MODULE_X11 "X11"
7217#define FPL__MODULE_GLX "GLX"
7222#define FPL__ENUM_COUNT(first, last) ((last) - (first) + 1)
7223#define FPL__ENUM_VALUE_TO_ARRAY_INDEX(value, first, last) (((value) >= (first) && (value) <= (last)) ? ((value) - (first)) : 0)
7238#if !defined(FPL__INTERNAL_LOGGING_DEFINED)
7239#define FPL__INTERNAL_LOGGING_DEFINED
7241#define FPL__MODULE_CONCAT(mod, format) "[" mod "] " format
7243#if defined(FPL__ENABLE_LOGGING)
7246#define FPL__LOGLEVEL_COUNT FPL__ENUM_COUNT(fplLogLevel_First, fplLogLevel_Last)
7261 const char *result = fpl__LogLevelNameTable[index];
7265fpl_internal void fpl__LogWrite(
const char *funcName,
const int lineNumber,
const fplLogLevel level,
const char *message) {
7268#if defined(FPL_LOG_MULTIPLE_WRITERS)
7269 settings->criticalWriter.console.logToError =
true;
7271 settings->errorWriter = settings->criticalWriter;
7272 settings->warningWriter = settings->criticalWriter;
7274 settings->verboseWriter = settings->infoWriter;
7283 if ((settings->
maxLevel == -1) || (level <= settings->maxLevel)) {
7284#if defined(FPL_LOG_MULTIPLE_WRITERS)
7290 const char *levelStr = fpl__LogLevelToString(level);
7306fpl_internal void fpl__LogWriteArgs(
const char *funcName,
const int lineNumber,
const fplLogLevel level,
const char *format, va_list argList) {
7308 va_copy(listCopy, argList);
7311 if (formattedLen > 0) {
7312 fpl__LogWrite(funcName, lineNumber, level, buffer);
7317fpl_internal void fpl__LogWriteVarArgs(
const char *funcName,
const int lineNumber,
const fplLogLevel level,
const char *format, ...) {
7319 va_start(argList, format);
7320 fpl__LogWriteArgs(funcName, lineNumber, level, format, argList);
7324# define FPL_LOG(lvl, mod, format, ...) fpl__LogWriteVarArgs(FPL_FUNCTION_NAME, __LINE__, lvl, FPL__MODULE_CONCAT(mod, format), ## __VA_ARGS__)
7325# define FPL_LOG_CRITICAL(mod, format, ...) FPL_LOG(fplLogLevel_Critical, mod, format, ## __VA_ARGS__)
7326# define FPL_LOG_ERROR(mod, format, ...) FPL_LOG(fplLogLevel_Error, mod, format, ## __VA_ARGS__)
7327# define FPL_LOG_WARN(mod, format, ...) FPL_LOG(fplLogLevel_Warning, mod, format, ## __VA_ARGS__)
7328# define FPL_LOG_INFO(mod, format, ...) FPL_LOG(fplLogLevel_Info, mod, format, ## __VA_ARGS__)
7329# define FPL_LOG_VERBOSE(mod, format, ...) FPL_LOG(fplLogLevel_Verbose, mod, format, ## __VA_ARGS__)
7330# define FPL_LOG_DEBUG(mod, format, ...) FPL_LOG(fplLogLevel_Debug, mod, format, ## __VA_ARGS__)
7331# define FPL_LOG_TRACE(mod, format, ...) FPL_LOG(fplLogLevel_Trace, mod, format, ## __VA_ARGS__)
7333# define FPL__LOG_FUNCTION_N(mod, name) FPL_LOG(fplLogLevel_Debug, mod, "-> %s()", name)
7334# define FPL_LOG_FUNCTION(mod) FPL__LOG_FUNCTION_N(mod, FPL_FUNCTION_NAME)
7338# define FPL_LOG(lvl, mod, format, ...)
7339# define FPL_LOG_CRITICAL(mod, format, ...)
7340# define FPL_LOG_ERROR(mod, format, ...)
7341# define FPL_LOG_WARN(mod, format, ...)
7342# define FPL_LOG_INFO(mod, format, ...)
7343# define FPL_LOG_VERBOSE(mod, format, ...)
7344# define FPL_LOG_DEBUG(mod, format, ...)
7345# define FPL_LOG_FUNCTION(mod)
7353#define FPL__M_CRITICAL(funcName, line, mod, format, ...) fpl__HandleError(funcName, line, fplLogLevel_Critical, FPL__MODULE_CONCAT(mod, format), ## __VA_ARGS__)
7354#define FPL__M_ERROR(funcName, line, mod, format, ...) fpl__HandleError(funcName, line, fplLogLevel_Error, FPL__MODULE_CONCAT(mod, format), ## __VA_ARGS__)
7355#define FPL__M_WARNING(funcName, line, mod, format, ...) fpl__HandleError(funcName, line, fplLogLevel_Warning, FPL__MODULE_CONCAT(mod, format), ## __VA_ARGS__)
7357#define FPL__CRITICAL(mod, format, ...) FPL__M_CRITICAL(FPL_FUNCTION_NAME, __LINE__, mod, format, ## __VA_ARGS__)
7358#define FPL__ERROR(mod, format, ...) FPL__M_ERROR(FPL_FUNCTION_NAME, __LINE__, mod, format, ## __VA_ARGS__)
7359#define FPL__WARNING(mod, format, ...) FPL__M_WARNING(FPL_FUNCTION_NAME, __LINE__, mod, format, ## __VA_ARGS__)
7368#if !defined(FPL__PLATFORM_CONSTANTS_DEFINED)
7369#define FPL__PLATFORM_CONSTANTS_DEFINED
7372#define FPL__ARBITARY_PADDING 64
7374#define FPL__MEMORY_PADDING sizeof(uintptr_t)
7378fpl_internal void fpl__HandleError(
const char *funcName,
const int lineNumber,
const fplLogLevel level,
const char *format, ...);
7406fpl_internal void *fpl__AllocateDynamicMemory(
const size_t size,
const size_t alignment);
7408fpl_internal void *fpl__AllocateTemporaryMemory(
const size_t size,
const size_t alignment);
7409fpl_internal void fpl__ReleaseTemporaryMemory(
void *ptr);
7411fpl_internal uint32_t fpl__NextPowerOfTwo(
const uint32_t input) {
7422fpl_internal uint32_t fpl__PrevPowerOfTwo(
const uint32_t input) {
7423 uint32_t result = fpl__NextPowerOfTwo(input) >> 1;
7427fpl_internal uint32_t fpl__RoundToPowerOfTwo(
const uint32_t input) {
7428 uint32_t prev = fpl__PrevPowerOfTwo(input);
7429 uint32_t next = fpl__NextPowerOfTwo(input);
7430 if ((next - input) < (input - prev)) {
7437fpl_internal bool fpl__AddLineWhenAnyMatches(
const char *line,
const char **wildcards,
const size_t maxWildcardCount,
const size_t maxLineSize,
const size_t maxLineCount,
char **outLines,
size_t *outCount) {
7438 for (
size_t i = 0; i < maxWildcardCount; ++i) {
7439 const char *wildcard = wildcards[i];
7441 size_t index = *outCount;
7442 char *target = outLines[index];
7444 *outCount = index + 1;
7448 bool result = *outCount < maxLineCount;
7452fpl_internal size_t fpl__ParseTextFile(
const char *filePath,
const char **wildcards,
const size_t maxWildcardCount,
const size_t maxLineSize,
const size_t maxLineCount,
char **outLines) {
7453 if (filePath ==
fpl_null || wildcards ==
fpl_null || maxWildcardCount == 0 || maxLineSize == 0 || maxLineCount == 0 || outLines ==
fpl_null) {
7462 char *line = (
char *)fpl__AllocateTemporaryMemory(maxLineSize, 8);
7465 size_t bytesRead = 0;
7466 size_t posLineBytes = 0;
7468 while (!done && ((bytesRead =
fplFileReadBlock(&fileHandle, maxBufferSize, &buffer[0], maxBufferSize)) > 0)) {
7469 buffer[bytesRead] = 0;
7470 char *start = &buffer[0];
7473 size_t lineSizeToRead = 0;
7474 while (readPos < bytesRead) {
7476 size_t remainingLineBytes = maxLineSize - posLineBytes;
7477 char *lineTargetP = line + posLineBytes;
7478 if (lineSizeToRead < remainingLineBytes) {
7481 fplCopyStringLen(start, remainingLineBytes - 1, lineTargetP, remainingLineBytes);
7483 if (!fpl__AddLineWhenAnyMatches(line, wildcards, maxWildcardCount, maxLineSize, maxLineCount, outLines, &result)) {
7500 if (lineSizeToRead > 0) {
7501 size_t remainingLineBytes = maxLineSize - posLineBytes;
7502 char *lineTargetP = line + posLineBytes;
7503 if (lineSizeToRead < remainingLineBytes) {
7505 posLineBytes += lineSizeToRead;
7506 if (bytesRead <= maxBufferSize) {
7507 if (!fpl__AddLineWhenAnyMatches(line, wildcards, maxWildcardCount, maxLineSize, maxLineCount, outLines, &result)) {
7512 fplCopyStringLen(start, remainingLineBytes - 1, lineTargetP, remainingLineBytes);
7516 if (!fpl__AddLineWhenAnyMatches(line, wildcards, maxWildcardCount, maxLineSize, maxLineCount, outLines, &result)) {
7522 fpl__ReleaseTemporaryMemory(line);
7531 const char *p = versionStr;
7532 for (
int i = 0; i < 4; ++i) {
7533 const char *digitStart = p;
7534 while (*p >=
'0' && *p <=
'9') {
7537 size_t len = p - digitStart;
7541 versionInfo->
values[i][0] = 0;
7543 if (*p !=
'.' && *p !=
'-')
break;
7563#if defined(FPL_PLATFORM_WINDOWS)
7564# include <windowsx.h>
7567# include <shellapi.h>
7569# if defined(FPL_IS_CPP)
7570# define fpl__Win32IsEqualGuid(a, b) InlineIsEqualGUID(a, b)
7572# define fpl__Win32IsEqualGuid(a, b) InlineIsEqualGUID(&a, &b)
7575fpl_internal const char *fpl__Win32FormatGuidString(
char *buffer,
const size_t maxBufferLen,
const GUID *guid) {
7576 fplStringFormat(buffer, maxBufferLen,
"{%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX}",
7577 guid->Data1, guid->Data2, guid->Data3,
7578 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
7579 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
7584#define FPL__WIN32_LOAD_LIBRARY_BREAK(mod, target, libName) \
7585 (target) = LoadLibraryA(libName); \
7586 if((target) == fpl_null) { \
7587 FPL__WARNING(mod, "Failed loading library '%s'", (libName)); \
7590#define FPL__WIN32_GET_FUNCTION_ADDRESS_BREAK(mod, libHandle, libName, target, type, name) \
7591 (target)->name = (type *)GetProcAddress(libHandle, #name); \
7592 if ((target)->name == fpl_null) { \
7593 FPL__WARNING(mod, "Failed getting procedure address '%s' from library '%s'", #name, libName); \
7596#if !defined(FPL_NO_RUNTIME_LINKING)
7597# define FPL__WIN32_LOAD_LIBRARY FPL__WIN32_LOAD_LIBRARY_BREAK
7598# define FPL__WIN32_GET_FUNCTION_ADDRESS FPL__WIN32_GET_FUNCTION_ADDRESS_BREAK
7600# define FPL__WIN32_LOAD_LIBRARY(mod, target, libName)
7601# define FPL__WIN32_GET_FUNCTION_ADDRESS(mod, libHandle, libName, target, type, name) \
7602 (target)->name = name
7608#define FPL__FUNC_XINPUT_XInputGetState(name) DWORD WINAPI name(DWORD dwUserIndex, XINPUT_STATE *pState)
7609typedef FPL__FUNC_XINPUT_XInputGetState(fpl__win32_func_XInputGetState);
7610FPL__FUNC_XINPUT_XInputGetState(fpl__Win32XInputGetStateStub) {
7611 return(ERROR_DEVICE_NOT_CONNECTED);
7613#define FPL__FUNC_XINPUT_XInputGetCapabilities(name) DWORD WINAPI name(DWORD dwUserIndex, DWORD dwFlags, XINPUT_CAPABILITIES* pCapabilities)
7614typedef FPL__FUNC_XINPUT_XInputGetCapabilities(fpl__win32_func_XInputGetCapabilities);
7615FPL__FUNC_XINPUT_XInputGetCapabilities(fpl__Win32XInputGetCapabilitiesStub) {
7616 return(ERROR_DEVICE_NOT_CONNECTED);
7618typedef struct fpl__Win32XInputApi {
7619 HMODULE xinputLibrary;
7620 fpl__win32_func_XInputGetState *XInputGetState;
7621 fpl__win32_func_XInputGetCapabilities *XInputGetCapabilities;
7622} fpl__Win32XInputApi;
7624fpl_internal void fpl__Win32UnloadXInputApi(fpl__Win32XInputApi *xinputApi) {
7626 if (xinputApi->xinputLibrary) {
7627 FPL_LOG_DEBUG(
"XInput",
"Unload XInput Library");
7628 FreeLibrary(xinputApi->xinputLibrary);
7629 xinputApi->xinputLibrary =
fpl_null;
7630 xinputApi->XInputGetState = fpl__Win32XInputGetStateStub;
7631 xinputApi->XInputGetCapabilities = fpl__Win32XInputGetCapabilitiesStub;
7635fpl_internal void fpl__Win32LoadXInputApi(fpl__Win32XInputApi *xinputApi) {
7637 const char *xinputFileNames[] = {
7642 bool result =
false;
7643 for (uint32_t index = 0; index <
fplArrayCount(xinputFileNames); ++index) {
7644 const char *libName = xinputFileNames[index];
7648 FPL__WIN32_LOAD_LIBRARY_BREAK(FPL__MODULE_XINPUT, libHandle, libName);
7649 xinputApi->xinputLibrary = libHandle;
7650 FPL__WIN32_GET_FUNCTION_ADDRESS_BREAK(FPL__MODULE_XINPUT, libHandle, libName, xinputApi, fpl__win32_func_XInputGetState, XInputGetState);
7651 FPL__WIN32_GET_FUNCTION_ADDRESS_BREAK(FPL__MODULE_XINPUT, libHandle, libName, xinputApi, fpl__win32_func_XInputGetCapabilities, XInputGetCapabilities);
7657 fpl__Win32UnloadXInputApi(xinputApi);
7661 xinputApi->XInputGetState = fpl__Win32XInputGetStateStub;
7662 xinputApi->XInputGetCapabilities = fpl__Win32XInputGetCapabilitiesStub;
7671#define FPL__FUNC_WIN32_ChoosePixelFormat(name) int WINAPI name(HDC hdc, CONST PIXELFORMATDESCRIPTOR *ppfd)
7672typedef FPL__FUNC_WIN32_ChoosePixelFormat(fpl__win32_func_ChoosePixelFormat);
7673#define FPL__FUNC_WIN32_SetPixelFormat(name) BOOL WINAPI name(HDC hdc, int format, CONST PIXELFORMATDESCRIPTOR *ppfd)
7674typedef FPL__FUNC_WIN32_SetPixelFormat(fpl__win32_func_SetPixelFormat);
7675#define FPL__FUNC_WIN32_DescribePixelFormat(name) int WINAPI name(HDC hdc, int iPixelFormat, UINT nBytes, LPPIXELFORMATDESCRIPTOR ppfd)
7676typedef FPL__FUNC_WIN32_DescribePixelFormat(fpl__win32_func_DescribePixelFormat);
7677#define FPL__FUNC_WIN32_GetDeviceCaps(name) int WINAPI name(HDC hdc, int index)
7678typedef FPL__FUNC_WIN32_GetDeviceCaps(fpl__win32_func_GetDeviceCaps);
7679#define FPL__FUNC_WIN32_StretchDIBits(name) int WINAPI name(HDC hdc, int xDest, int yDest, int DestWidth, int DestHeight, int xSrc, int ySrc, int SrcWidth, int SrcHeight, CONST VOID *lpBits, CONST BITMAPINFO *lpbmi, UINT iUsage, DWORD rop)
7680typedef FPL__FUNC_WIN32_StretchDIBits(fpl__win32_func_StretchDIBits);
7681#define FPL__FUNC_WIN32_DeleteObject(name) BOOL WINAPI name( _In_ HGDIOBJ ho)
7682typedef FPL__FUNC_WIN32_DeleteObject(fpl__win32_func_DeleteObject);
7683#define FPL__FUNC_WIN32_SwapBuffers(name) BOOL WINAPI name(HDC)
7684typedef FPL__FUNC_WIN32_SwapBuffers(fpl__win32_func_SwapBuffers);
7685#define FPL__FUNC_WIN32_CreateDIBSection(name) HBITMAP WINAPI name(HDC hdc, CONST BITMAPINFO *pbmi, UINT usage, VOID **ppvBits, HANDLE hSection, DWORD offset)
7686typedef FPL__FUNC_WIN32_CreateDIBSection(fpl__win32_func_CreateDIBSection);
7687#define FPL__FUNC_WIN32_CreateBitmap(name) HBITMAP WINAPI name(int nWidth, int nHeight, UINT nPlanes, UINT nBitCount, CONST VOID *lpBits)
7688typedef FPL__FUNC_WIN32_CreateBitmap(fpl__win32_func_CreateBitmap);
7689#define FPL__FUNC_WIN32_CreateSolidBrush(name) HBRUSH WINAPI name(COLORREF color)
7690typedef FPL__FUNC_WIN32_CreateSolidBrush(fpl__win32_func_CreateSolidBrush);
7693#define FPL__FUNC_WIN32_SHGetFolderPathW(name) HRESULT WINAPI name(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath)
7694typedef FPL__FUNC_WIN32_SHGetFolderPathW(fpl__win32_func_SHGetFolderPathW);
7695#define FPL__FUNC_WIN32_DragQueryFileW(name) UINT WINAPI name(HDROP hDrop, UINT iFile, LPWSTR lpszFile, UINT cch)
7696typedef FPL__FUNC_WIN32_DragQueryFileW(fpl__win32_func_DragQueryFileW);
7697#define FPL__FUNC_WIN32_DragAcceptFiles(name) void WINAPI name(HWND hWnd, BOOL fAccept)
7698typedef FPL__FUNC_WIN32_DragAcceptFiles(fpl__win32_func_DragAcceptFiles);
7701#define FPL__FUNC_WIN32_RegisterClassExW(name) ATOM WINAPI name(CONST WNDCLASSEXW *)
7702typedef FPL__FUNC_WIN32_RegisterClassExW(fpl__win32_func_RegisterClassExW);
7703#define FPL__FUNC_WIN32_UnregisterClassW(name) BOOL WINAPI name(LPCWSTR lpClassName, HINSTANCE hInstance)
7704typedef FPL__FUNC_WIN32_UnregisterClassW(fpl__win32_func_UnregisterClassW);
7705#define FPL__FUNC_WIN32_ShowWindow(name) BOOL WINAPI name(HWND hWnd, int nCmdShow)
7706typedef FPL__FUNC_WIN32_ShowWindow(fpl__win32_func_ShowWindow);
7707#define FPL__FUNC_WIN32_DestroyWindow(name) BOOL WINAPI name(HWND hWnd)
7708typedef FPL__FUNC_WIN32_DestroyWindow(fpl__win32_func_DestroyWindow);
7709#define FPL__FUNC_WIN32_UpdateWindow(name) BOOL WINAPI name(HWND hWnd)
7710typedef FPL__FUNC_WIN32_UpdateWindow(fpl__win32_func_UpdateWindow);
7711#define FPL__FUNC_WIN32_TranslateMessage(name) BOOL WINAPI name(CONST MSG *lpMsg)
7712typedef FPL__FUNC_WIN32_TranslateMessage(fpl__win32_func_TranslateMessage);
7713#define FPL__FUNC_WIN32_DispatchMessageW(name) LRESULT WINAPI name(CONST MSG *lpMsg)
7714typedef FPL__FUNC_WIN32_DispatchMessageW(fpl__win32_func_DispatchMessageW);
7715#define FPL__FUNC_WIN32_PeekMessageW(name) BOOL WINAPI name(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg)
7716typedef FPL__FUNC_WIN32_PeekMessageW(fpl__win32_func_PeekMessageW);
7717#define FPL__FUNC_WIN32_DefWindowProcW(name) LRESULT WINAPI name(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
7718typedef FPL__FUNC_WIN32_DefWindowProcW(fpl__win32_func_DefWindowProcW);
7719#define FPL__FUNC_WIN32_CreateWindowExW(name) HWND WINAPI name(DWORD dwExStyle, LPCWSTR lpClassName, LPCWSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam)
7720typedef FPL__FUNC_WIN32_CreateWindowExW(fpl__win32_func_CreateWindowExW);
7721#define FPL__FUNC_WIN32_SetWindowPos(name) BOOL WINAPI name(HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags)
7722typedef FPL__FUNC_WIN32_SetWindowPos(fpl__win32_func_SetWindowPos);
7723#define FPL__FUNC_WIN32_GetWindowPlacement(name) BOOL WINAPI name(HWND hWnd, WINDOWPLACEMENT *lpwndpl)
7724typedef FPL__FUNC_WIN32_GetWindowPlacement(fpl__win32_func_GetWindowPlacement);
7725#define FPL__FUNC_WIN32_SetWindowPlacement(name) BOOL WINAPI name(HWND hWnd, CONST WINDOWPLACEMENT *lpwndpl)
7726typedef FPL__FUNC_WIN32_SetWindowPlacement(fpl__win32_func_SetWindowPlacement);
7727#define FPL__FUNC_WIN32_GetClientRect(name) BOOL WINAPI name(HWND hWnd, LPRECT lpRect)
7728typedef FPL__FUNC_WIN32_GetClientRect(fpl__win32_func_GetClientRect);
7729#define FPL__FUNC_WIN32_GetWindowRect(name) BOOL WINAPI name(HWND hWnd, LPRECT lpRect)
7730typedef FPL__FUNC_WIN32_GetWindowRect(fpl__win32_func_GetWindowRect);
7731#define FPL__FUNC_WIN32_AdjustWindowRect(name) BOOL WINAPI name(LPRECT lpRect, DWORD dwStyle, BOOL bMenu)
7732typedef FPL__FUNC_WIN32_AdjustWindowRect(fpl__win32_func_AdjustWindowRect);
7733#define FPL__FUNC_WIN32_ClientToScreen(name) BOOL WINAPI name(HWND hWnd, LPPOINT lpPoint)
7734typedef FPL__FUNC_WIN32_ClientToScreen(fpl__win32_func_ClientToScreen);
7735#define FPL__FUNC_WIN32_GetAsyncKeyState(name) SHORT WINAPI name(int vKey)
7736typedef FPL__FUNC_WIN32_GetAsyncKeyState(fpl__win32_func_GetAsyncKeyState);
7737#define FPL__FUNC_WIN32_GetKeyState(name) SHORT WINAPI name(int vKey)
7738typedef FPL__FUNC_WIN32_GetKeyState(fpl__win32_func_GetKeyState);
7739#define FPL__FUNC_WIN32_MapVirtualKeyW(name) UINT WINAPI name(UINT uCode, UINT uMapType)
7740typedef FPL__FUNC_WIN32_MapVirtualKeyW(fpl__win32_func_MapVirtualKeyW);
7741#define FPL__FUNC_WIN32_SetCursor(name) HCURSOR WINAPI name(HCURSOR hCursor)
7742typedef FPL__FUNC_WIN32_SetCursor(fpl__win32_func_SetCursor);
7743#define FPL__FUNC_WIN32_GetCursor(name) HCURSOR WINAPI name(VOID)
7744typedef FPL__FUNC_WIN32_GetCursor(fpl__win32_func_GetCursor);
7745#define FPL__FUNC_WIN32_GetCursorPos(name) BOOL WINAPI name(LPPOINT lpPoint)
7746typedef FPL__FUNC_WIN32_GetCursorPos(fpl__win32_func_GetCursorPos);
7747#define FPL__FUNC_WIN32_WindowFromPoint(name) HWND WINAPI name(POINT Point)
7748typedef FPL__FUNC_WIN32_WindowFromPoint(fpl__win32_func_WindowFromPoint);
7749#define FPL__FUNC_WIN32_PtInRect(name) BOOL WINAPI name(CONST RECT *lprc, POINT pt)
7750typedef FPL__FUNC_WIN32_PtInRect(fpl__win32_func_PtInRect);
7751#define FPL__FUNC_WIN32_LoadCursorA(name) HCURSOR WINAPI name(HINSTANCE hInstance, LPCSTR lpCursorName)
7752typedef FPL__FUNC_WIN32_LoadCursorA(fpl__win32_func_LoadCursorA);
7753#define FPL__FUNC_WIN32_LoadCursorW(name) HCURSOR WINAPI name(HINSTANCE hInstance, LPCWSTR lpCursorName)
7754typedef FPL__FUNC_WIN32_LoadCursorW(fpl__win32_func_LoadCursorW);
7755#define FPL__FUNC_WIN32_LoadIconA(name) HICON WINAPI name(HINSTANCE hInstance, LPCSTR lpIconName)
7756typedef FPL__FUNC_WIN32_LoadIconA(fpl__win32_func_LoadIconA);
7757#define FPL__FUNC_WIN32_LoadIconW(name) HICON WINAPI name(HINSTANCE hInstance, LPCWSTR lpIconName)
7758typedef FPL__FUNC_WIN32_LoadIconW(fpl__win32_func_LoadIconW);
7759#define FPL__FUNC_WIN32_SetWindowTextW(name) BOOL WINAPI name(HWND hWnd, LPCWSTR lpString)
7760typedef FPL__FUNC_WIN32_SetWindowTextW(fpl__win32_func_SetWindowTextW);
7761#define FPL__FUNC_WIN32_GetWindowTextW(name) int WINAPI name(HWND hWnd, LPWSTR lpString, int nMaxCount)
7762typedef FPL__FUNC_WIN32_GetWindowTextW(fpl__win32_func_GetWindowTextW);
7763#define FPL__FUNC_WIN32_SetWindowLongW(name) LONG WINAPI name(HWND hWnd, int nIndex, LONG dwNewLong)
7764typedef FPL__FUNC_WIN32_SetWindowLongW(fpl__win32_func_SetWindowLongW);
7765#define FPL__FUNC_WIN32_GetWindowLongW(name) LONG WINAPI name(HWND hWnd, int nIndex)
7766typedef FPL__FUNC_WIN32_GetWindowLongW(fpl__win32_func_GetWindowLongW);
7768#if defined(FPL_ARCH_X64)
7769#define FPL__FUNC_WIN32_SetWindowLongPtrW(name) LONG_PTR WINAPI name(HWND hWnd, int nIndex, LONG_PTR dwNewLong)
7770typedef FPL__FUNC_WIN32_SetWindowLongPtrW(fpl__win32_func_SetWindowLongPtrW);
7771#define FPL__FUNC_WIN32_GetWindowLongPtrW(name) LONG_PTR WINAPI name(HWND hWnd, int nIndex)
7772typedef FPL__FUNC_WIN32_GetWindowLongPtrW(fpl__win32_func_GetWindowLongPtrW);
7775#define FPL__FUNC_WIN32_ReleaseDC(name) int WINAPI name(HWND hWnd, HDC hDC)
7776typedef FPL__FUNC_WIN32_ReleaseDC(fpl__win32_func_ReleaseDC);
7777#define FPL__FUNC_WIN32_GetDC(name) HDC WINAPI name(HWND hWnd)
7778typedef FPL__FUNC_WIN32_GetDC(fpl__win32_func_GetDC);
7779#define FPL__FUNC_WIN32_ChangeDisplaySettingsW(name) LONG WINAPI name(DEVMODEW* lpDevMode, DWORD dwFlags)
7780typedef FPL__FUNC_WIN32_ChangeDisplaySettingsW(fpl__win32_func_ChangeDisplaySettingsW);
7781#define FPL__FUNC_WIN32_EnumDisplaySettingsW(name) BOOL WINAPI name(LPCWSTR lpszDeviceName, DWORD iModeNum, DEVMODEW* lpDevMode)
7782typedef FPL__FUNC_WIN32_EnumDisplaySettingsW(fpl__win32_func_EnumDisplaySettingsW);
7783#define FPL__FUNC_WIN32_OpenClipboard(name) BOOL WINAPI name(HWND hWndNewOwner)
7784typedef FPL__FUNC_WIN32_OpenClipboard(fpl__win32_func_OpenClipboard);
7785#define FPL__FUNC_WIN32_CloseClipboard(name) BOOL WINAPI name(VOID)
7786typedef FPL__FUNC_WIN32_CloseClipboard(fpl__win32_func_CloseClipboard);
7787#define FPL__FUNC_WIN32_EmptyClipboard(name) BOOL WINAPI name(VOID)
7788typedef FPL__FUNC_WIN32_EmptyClipboard(fpl__win32_func_EmptyClipboard);
7789#define FPL__FUNC_WIN32_IsClipboardFormatAvailable(name) BOOL WINAPI name(UINT format)
7790typedef FPL__FUNC_WIN32_IsClipboardFormatAvailable(fpl__win32_func_IsClipboardFormatAvailable);
7791#define FPL__FUNC_WIN32_SetClipboardData(name) HANDLE WINAPI name(UINT uFormat, HANDLE hMem)
7792typedef FPL__FUNC_WIN32_SetClipboardData(fpl__win32_func_SetClipboardData);
7793#define FPL__FUNC_WIN32_GetClipboardData(name) HANDLE WINAPI name(UINT uFormat)
7794typedef FPL__FUNC_WIN32_GetClipboardData(fpl__win32_func_GetClipboardData);
7795#define FPL__FUNC_WIN32_GetDesktopWindow(name) HWND WINAPI name(VOID)
7796typedef FPL__FUNC_WIN32_GetDesktopWindow(fpl__win32_func_GetDesktopWindow);
7797#define FPL__FUNC_WIN32_GetForegroundWindow(name) HWND WINAPI name(VOID)
7798typedef FPL__FUNC_WIN32_GetForegroundWindow(fpl__win32_func_GetForegroundWindow);
7799#define FPL__FUNC_WIN32_IsZoomed(name) BOOL WINAPI name(HWND hWnd)
7800typedef FPL__FUNC_WIN32_IsZoomed(fpl__win32_func_IsZoomed);
7801#define FPL__FUNC_WIN32_IsIconic(name) BOOL WINAPI name(HWND hWnd)
7802typedef FPL__FUNC_WIN32_IsIconic(fpl__win32_func_IsIconic);
7803#define FPL__FUNC_WIN32_SendMessageW(name) LRESULT WINAPI name(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
7804typedef FPL__FUNC_WIN32_SendMessageW(fpl__win32_func_SendMessageW);
7805#define FPL__FUNC_WIN32_GetMonitorInfoW(name) BOOL WINAPI name(HMONITOR hMonitor, LPMONITORINFO lpmi)
7806typedef FPL__FUNC_WIN32_GetMonitorInfoW(fpl__win32_func_GetMonitorInfoW);
7807#define FPL__FUNC_WIN32_EnumDisplayMonitors(name) BOOL WINAPI name(HDC hdc, LPCRECT lprcClip, MONITORENUMPROC lpfnEnum,LPARAM dwData)
7808typedef FPL__FUNC_WIN32_EnumDisplayMonitors(fpl__win32_func_EnumDisplayMonitors);
7809#define FPL__FUNC_WIN32_MonitorFromRect(name) HMONITOR WINAPI name(LPCRECT lprc, DWORD dwFlags)
7810typedef FPL__FUNC_WIN32_MonitorFromRect(fpl__win32_func_MonitorFromRect);
7811#define FPL__FUNC_WIN32_MonitorFromPoint(name) HMONITOR WINAPI name(POINT pt, DWORD dwFlags)
7812typedef FPL__FUNC_WIN32_MonitorFromPoint(fpl__win32_func_MonitorFromPoint);
7813#define FPL__FUNC_WIN32_MonitorFromWindow(name) HMONITOR WINAPI name(HWND hwnd, DWORD dwFlags)
7814typedef FPL__FUNC_WIN32_MonitorFromWindow(fpl__win32_func_MonitorFromWindow);
7815#define FPL__FUNC_WIN32_RegisterRawInputDevices(name) BOOL WINAPI name(PCRAWINPUTDEVICE pRawInputDevices, UINT uiNumDevices, UINT cbSize)
7816typedef FPL__FUNC_WIN32_RegisterRawInputDevices(fpl__win32_func_RegisterRawInputDevices);
7817#define FPL__FUNC_WIN32_ClipCursor(name) BOOL WINAPI name(CONST RECT *lpRect)
7818typedef FPL__FUNC_WIN32_ClipCursor(fpl__win32_func_ClipCursor);
7819#define FPL__FUNC_WIN32_PostQuitMessage(name) VOID WINAPI name(int nExitCode)
7820typedef FPL__FUNC_WIN32_PostQuitMessage(fpl__win32_func_PostQuitMessage);
7821#define FPL__FUNC_WIN32_CreateIconIndirect(name) HICON WINAPI name(PICONINFO piconinfo)
7822typedef FPL__FUNC_WIN32_CreateIconIndirect(fpl__win32_func_CreateIconIndirect);
7823#define FPL__FUNC_WIN32_GetKeyboardLayout(name) HKL WINAPI name(DWORD idThread)
7824typedef FPL__FUNC_WIN32_GetKeyboardLayout(fpl__win32_func_GetKeyboardLayout);
7825#define FPL__FUNC_WIN32_SetCapture(name) HWND WINAPI name(HWND hWnd)
7826typedef FPL__FUNC_WIN32_SetCapture(fpl__win32_func_SetCapture);
7827#define FPL__FUNC_WIN32_ReleaseCapture(name) BOOL WINAPI name(VOID)
7828typedef FPL__FUNC_WIN32_ReleaseCapture(fpl__win32_func_ReleaseCapture);
7829#define FPL__FUNC_WIN32_ScreenToClient(name) BOOL WINAPI name(HWND hWnd, LPPOINT lpPoint)
7830typedef FPL__FUNC_WIN32_ScreenToClient(fpl__win32_func_ScreenToClient);
7831#define FPL__FUNC_WIN32_BeginPaint(name) HDC WINAPI name(_In_ HWND hWnd, _Out_ LPPAINTSTRUCT lpPaint)
7832typedef FPL__FUNC_WIN32_BeginPaint(fpl__win32_func_BeginPaint);
7833#define FPL__FUNC_WIN32_EndPaint(name) BOOL WINAPI name(_In_ HWND hWnd, _In_ CONST PAINTSTRUCT *lpPaint)
7834typedef FPL__FUNC_WIN32_EndPaint(fpl__win32_func_EndPaint);
7835#define FPL__FUNC_WIN32_SetForegroundWindow(name) BOOL WINAPI name(_In_ HWND hWnd)
7836typedef FPL__FUNC_WIN32_SetForegroundWindow(fpl__win32_func_SetForegroundWindow);
7837#define FPL__FUNC_WIN32_SetFocus(name) HWND WINAPI name(_In_opt_ HWND hWnd)
7838typedef FPL__FUNC_WIN32_SetFocus(fpl__win32_func_SetFocus);
7839#define FPL__FUNC_WIN32_SetTimer(name) UINT_PTR WINAPI name(_In_opt_ HWND hWnd, _In_ UINT_PTR nIDEvent, _In_ UINT uElapse, _In_opt_ TIMERPROC lpTimerFunc)
7840typedef FPL__FUNC_WIN32_SetTimer(fpl__win32_func_SetTimer);
7841#define FPL__FUNC_WIN32_GetSysColorBrush(name) HBRUSH WINAPI name(_In_ int nIndex)
7842typedef FPL__FUNC_WIN32_GetSysColorBrush(fpl__win32_func_GetSysColorBrush);
7843#define FPL__FUNC_WIN32_GetSysColorBrush(name) HBRUSH WINAPI name(_In_ int nIndex)
7844typedef FPL__FUNC_WIN32_GetSysColorBrush(fpl__win32_func_GetSysColorBrush);
7847#define FPL__FUNC_WIN32_CoInitializeEx(name) HRESULT WINAPI name(LPVOID pvReserved, DWORD dwCoInit)
7848typedef FPL__FUNC_WIN32_CoInitializeEx(fpl__win32_func_CoInitializeEx);
7849#define FPL__FUNC_WIN32_CoUninitialize(name) void WINAPI name(void)
7850typedef FPL__FUNC_WIN32_CoUninitialize(fpl__win32_func_CoUninitialize);
7851#define FPL__FUNC_WIN32_CoCreateInstance(name) HRESULT WINAPI name(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID riid, LPVOID *ppv)
7852typedef FPL__FUNC_WIN32_CoCreateInstance(fpl__win32_func_CoCreateInstance);
7853#define FPL__FUNC_WIN32_CoTaskMemFree(name) void WINAPI name(LPVOID pv)
7854typedef FPL__FUNC_WIN32_CoTaskMemFree(fpl__win32_func_CoTaskMemFree);
7855#define FPL__FUNC_WIN32_PropVariantClear(name) HRESULT WINAPI name(PROPVARIANT *pvar)
7856typedef FPL__FUNC_WIN32_PropVariantClear(fpl__win32_func_PropVariantClear);
7858typedef struct fpl__Win32GdiApi {
7860 fpl__win32_func_ChoosePixelFormat *ChoosePixelFormat;
7861 fpl__win32_func_SetPixelFormat *SetPixelFormat;
7862 fpl__win32_func_DescribePixelFormat *DescribePixelFormat;
7863 fpl__win32_func_GetDeviceCaps *GetDeviceCaps;
7864 fpl__win32_func_StretchDIBits *StretchDIBits;
7865 fpl__win32_func_DeleteObject *DeleteObject;
7866 fpl__win32_func_SwapBuffers *SwapBuffers;
7867 fpl__win32_func_CreateDIBSection *CreateDIBSection;
7868 fpl__win32_func_CreateBitmap *CreateBitmap;
7869 fpl__win32_func_CreateSolidBrush *CreateSolidBrush;
7872typedef struct fpl__Win32ShellApi {
7873 HMODULE shellLibrary;
7874 fpl__win32_func_SHGetFolderPathW *SHGetFolderPathW;
7875 fpl__win32_func_DragQueryFileW *DragQueryFileW;
7876 fpl__win32_func_DragAcceptFiles *DragAcceptFiles;
7877} fpl__Win32ShellApi;
7879typedef struct fpl__Win32UserApi {
7880 HMODULE userLibrary;
7881 fpl__win32_func_RegisterClassExW *RegisterClassExW;
7882 fpl__win32_func_UnregisterClassW *UnregisterClassW;
7883 fpl__win32_func_ShowWindow *ShowWindow;
7884 fpl__win32_func_DestroyWindow *DestroyWindow;
7885 fpl__win32_func_UpdateWindow *UpdateWindow;
7886 fpl__win32_func_TranslateMessage *TranslateMessage;
7887 fpl__win32_func_DispatchMessageW *DispatchMessageW;
7888 fpl__win32_func_PeekMessageW *PeekMessageW;
7889 fpl__win32_func_DefWindowProcW *DefWindowProcW;
7890 fpl__win32_func_CreateWindowExW *CreateWindowExW;
7891 fpl__win32_func_SetWindowPos *SetWindowPos;
7892 fpl__win32_func_GetWindowPlacement *GetWindowPlacement;
7893 fpl__win32_func_SetWindowPlacement *SetWindowPlacement;
7894 fpl__win32_func_GetClientRect *GetClientRect;
7895 fpl__win32_func_GetWindowRect *GetWindowRect;
7896 fpl__win32_func_AdjustWindowRect *AdjustWindowRect;
7897 fpl__win32_func_GetAsyncKeyState *GetAsyncKeyState;
7898 fpl__win32_func_MapVirtualKeyW *MapVirtualKeyW;
7899 fpl__win32_func_SetCursor *SetCursor;
7900 fpl__win32_func_GetCursor *GetCursor;
7901 fpl__win32_func_LoadCursorA *LoadCursorA;
7902 fpl__win32_func_LoadCursorW *LoadCursorW;
7903 fpl__win32_func_LoadIconA *LoadIconA;
7904 fpl__win32_func_LoadIconW *LoadIconW;
7905 fpl__win32_func_SetWindowTextW *SetWindowTextW;
7906 fpl__win32_func_GetWindowTextW *GetWindowTextW;
7907 fpl__win32_func_SetWindowLongW *SetWindowLongW;
7908 fpl__win32_func_GetWindowLongW *GetWindowLongW;
7909#if defined(FPL_ARCH_X64)
7910 fpl__win32_func_SetWindowLongPtrW *SetWindowLongPtrW;
7911 fpl__win32_func_GetWindowLongPtrW *GetWindowLongPtrW;
7913 fpl__win32_func_ReleaseDC *ReleaseDC;
7914 fpl__win32_func_GetDC *GetDC;
7915 fpl__win32_func_ChangeDisplaySettingsW *ChangeDisplaySettingsW;
7916 fpl__win32_func_EnumDisplaySettingsW *EnumDisplaySettingsW;
7917 fpl__win32_func_OpenClipboard *OpenClipboard;
7918 fpl__win32_func_CloseClipboard *CloseClipboard;
7919 fpl__win32_func_EmptyClipboard *EmptyClipboard;
7920 fpl__win32_func_IsClipboardFormatAvailable *IsClipboardFormatAvailable;
7921 fpl__win32_func_SetClipboardData *SetClipboardData;
7922 fpl__win32_func_GetClipboardData *GetClipboardData;
7923 fpl__win32_func_GetDesktopWindow *GetDesktopWindow;
7924 fpl__win32_func_GetForegroundWindow *GetForegroundWindow;
7925 fpl__win32_func_IsZoomed *IsZoomed;
7926 fpl__win32_func_IsIconic *IsIconic;
7927 fpl__win32_func_SendMessageW *SendMessageW;
7928 fpl__win32_func_GetMonitorInfoW *GetMonitorInfoW;
7929 fpl__win32_func_EnumDisplayMonitors *EnumDisplayMonitors;
7930 fpl__win32_func_MonitorFromRect *MonitorFromRect;
7931 fpl__win32_func_MonitorFromPoint *MonitorFromPoint;
7932 fpl__win32_func_MonitorFromWindow *MonitorFromWindow;
7933 fpl__win32_func_GetCursorPos *GetCursorPos;
7934 fpl__win32_func_WindowFromPoint *WindowFromPoint;
7935 fpl__win32_func_ClientToScreen *ClientToScreen;
7936 fpl__win32_func_PtInRect *PtInRect;
7937 fpl__win32_func_RegisterRawInputDevices *RegisterRawInputDevices;
7938 fpl__win32_func_ClipCursor *ClipCursor;
7939 fpl__win32_func_PostQuitMessage *PostQuitMessage;
7940 fpl__win32_func_CreateIconIndirect *CreateIconIndirect;
7941 fpl__win32_func_GetKeyboardLayout *GetKeyboardLayout;
7942 fpl__win32_func_GetKeyState *GetKeyState;
7943 fpl__win32_func_SetCapture *SetCapture;
7944 fpl__win32_func_ReleaseCapture *ReleaseCapture;
7945 fpl__win32_func_ScreenToClient *ScreenToClient;
7946 fpl__win32_func_BeginPaint *BeginPaint;
7947 fpl__win32_func_EndPaint *EndPaint;
7948 fpl__win32_func_SetForegroundWindow *SetForegroundWindow;
7949 fpl__win32_func_SetFocus *SetFocus;
7950 fpl__win32_func_SetTimer *SetTimer;
7951 fpl__win32_func_GetSysColorBrush *GetSysColorBrush;
7954typedef struct fpl__Win32OleApi {
7956 fpl__win32_func_CoInitializeEx *CoInitializeEx;
7957 fpl__win32_func_CoUninitialize *CoUninitialize;
7958 fpl__win32_func_CoCreateInstance *CoCreateInstance;
7959 fpl__win32_func_CoTaskMemFree *CoTaskMemFree;
7960 fpl__win32_func_PropVariantClear *PropVariantClear;
7963typedef struct fpl__Win32Api {
7964 fpl__Win32GdiApi gdi;
7965 fpl__Win32ShellApi shell;
7966 fpl__Win32UserApi user;
7967 fpl__Win32OleApi ole;
7971fpl_internal void fpl__Win32UnloadApi(fpl__Win32Api *wapi) {
7973 if (wapi->ole.oleLibrary !=
fpl_null) {
7974 FreeLibrary(wapi->ole.oleLibrary);
7977 if (wapi->gdi.gdiLibrary !=
fpl_null) {
7978 FreeLibrary(wapi->gdi.gdiLibrary);
7981 if (wapi->user.userLibrary !=
fpl_null) {
7982 FreeLibrary(wapi->user.userLibrary);
7985 if (wapi->shell.shellLibrary !=
fpl_null) {
7986 FreeLibrary(wapi->shell.shellLibrary);
7989 wapi->isValid =
false;
7992fpl_internal bool fpl__Win32LoadApi(fpl__Win32Api *wapi) {
7994 bool result =
false;
7998 const char *shellLibraryName =
"shell32.dll";
8000 FPL__WIN32_LOAD_LIBRARY(FPL__MODULE_WIN32, shellLibrary, shellLibraryName);
8001 wapi->shell.shellLibrary = shellLibrary;
8002 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, shellLibrary, shellLibraryName, &wapi->shell, fpl__win32_func_SHGetFolderPathW, SHGetFolderPathW);
8003 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, shellLibrary, shellLibraryName, &wapi->shell, fpl__win32_func_DragQueryFileW, DragQueryFileW);
8004 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, shellLibrary, shellLibraryName, &wapi->shell, fpl__win32_func_DragAcceptFiles, DragAcceptFiles);
8007 const char *userLibraryName =
"user32.dll";
8009 FPL__WIN32_LOAD_LIBRARY(FPL__MODULE_WIN32, userLibrary, userLibraryName);
8010 wapi->user.userLibrary = userLibrary;
8011 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_RegisterClassExW, RegisterClassExW);
8012 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_UnregisterClassW, UnregisterClassW);
8013 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_ShowWindow, ShowWindow);
8014 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_DestroyWindow, DestroyWindow);
8015 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_UpdateWindow, UpdateWindow);
8016 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_TranslateMessage, TranslateMessage);
8017 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_DispatchMessageW, DispatchMessageW);
8018 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_PeekMessageW, PeekMessageW);
8019 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_DefWindowProcW, DefWindowProcW);
8020 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_CreateWindowExW, CreateWindowExW);
8021 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_SetWindowPos, SetWindowPos);
8022 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_GetWindowPlacement, GetWindowPlacement);
8023 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_SetWindowPlacement, SetWindowPlacement);
8024 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_GetClientRect, GetClientRect);
8025 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_GetWindowRect, GetWindowRect);
8026 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_AdjustWindowRect, AdjustWindowRect);
8027 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_GetAsyncKeyState, GetAsyncKeyState);
8028 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_MapVirtualKeyW, MapVirtualKeyW);
8029 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_SetCursor, SetCursor);
8030 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_GetCursor, GetCursor);
8031 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_LoadCursorA, LoadCursorA);
8032 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_LoadCursorW, LoadCursorW);
8033 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_GetCursorPos, GetCursorPos);
8034 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_WindowFromPoint, WindowFromPoint);
8035 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_LoadIconA, LoadIconA);
8036 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_LoadIconW, LoadIconW);
8037 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_SetWindowTextW, SetWindowTextW);
8038 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_SetWindowLongW, SetWindowLongW);
8039 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_GetWindowLongW, GetWindowLongW);
8041# if defined(FPL_ARCH_X64)
8042 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_SetWindowLongPtrW, SetWindowLongPtrW);
8043 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_GetWindowLongPtrW, GetWindowLongPtrW);
8046 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_ReleaseDC, ReleaseDC);
8047 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_GetDC, GetDC);
8048 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_ChangeDisplaySettingsW, ChangeDisplaySettingsW);
8049 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_EnumDisplaySettingsW, EnumDisplaySettingsW);
8050 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_IsClipboardFormatAvailable, IsClipboardFormatAvailable);
8051 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_OpenClipboard, OpenClipboard);
8052 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_CloseClipboard, CloseClipboard);
8053 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_EmptyClipboard, EmptyClipboard);
8054 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_SetClipboardData, SetClipboardData);
8055 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_GetClipboardData, GetClipboardData);
8056 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_GetDesktopWindow, GetDesktopWindow);
8057 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_GetForegroundWindow, GetForegroundWindow);
8058 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_IsZoomed, IsZoomed);
8059 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_IsIconic, IsIconic);
8060 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_SendMessageW, SendMessageW);
8061 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_GetMonitorInfoW, GetMonitorInfoW);
8062 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_EnumDisplayMonitors, EnumDisplayMonitors);
8063 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_MonitorFromRect, MonitorFromRect);
8064 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_MonitorFromPoint, MonitorFromPoint);
8065 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_MonitorFromWindow, MonitorFromWindow);
8066 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_ClientToScreen, ClientToScreen);
8067 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_PtInRect, PtInRect);
8068 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_RegisterRawInputDevices, RegisterRawInputDevices);
8069 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_ClipCursor, ClipCursor);
8070 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_PostQuitMessage, PostQuitMessage);
8071 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_CreateIconIndirect, CreateIconIndirect);
8072 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_GetKeyboardLayout, GetKeyboardLayout);
8073 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_GetKeyState, GetKeyState);
8074 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_SetCapture, SetCapture);
8075 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_ReleaseCapture, ReleaseCapture);
8076 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_ScreenToClient, ScreenToClient);
8077 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_BeginPaint, BeginPaint);
8078 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_EndPaint, EndPaint);
8079 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_SetForegroundWindow, SetForegroundWindow);
8080 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_SetFocus, SetFocus);
8081 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_SetTimer, SetTimer);
8082 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, userLibrary, userLibraryName, &wapi->user, fpl__win32_func_GetSysColorBrush, GetSysColorBrush);
8085 const char *gdiLibraryName =
"gdi32.dll";
8087 FPL__WIN32_LOAD_LIBRARY(FPL__MODULE_WIN32, gdiLibrary, gdiLibraryName);
8088 wapi->gdi.gdiLibrary = gdiLibrary;
8089 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, gdiLibrary, gdiLibraryName, &wapi->gdi, fpl__win32_func_ChoosePixelFormat, ChoosePixelFormat);
8090 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, gdiLibrary, gdiLibraryName, &wapi->gdi, fpl__win32_func_SetPixelFormat, SetPixelFormat);
8091 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, gdiLibrary, gdiLibraryName, &wapi->gdi, fpl__win32_func_DescribePixelFormat, DescribePixelFormat);
8092 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, gdiLibrary, gdiLibraryName, &wapi->gdi, fpl__win32_func_StretchDIBits, StretchDIBits);
8093 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, gdiLibrary, gdiLibraryName, &wapi->gdi, fpl__win32_func_DeleteObject, DeleteObject);
8094 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, gdiLibrary, gdiLibraryName, &wapi->gdi, fpl__win32_func_SwapBuffers, SwapBuffers);
8095 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, gdiLibrary, gdiLibraryName, &wapi->gdi, fpl__win32_func_GetDeviceCaps, GetDeviceCaps);
8096 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, gdiLibrary, gdiLibraryName, &wapi->gdi, fpl__win32_func_CreateDIBSection, CreateDIBSection);
8097 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, gdiLibrary, gdiLibraryName, &wapi->gdi, fpl__win32_func_CreateBitmap, CreateBitmap);
8098 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, gdiLibrary, gdiLibraryName, &wapi->gdi, fpl__win32_func_CreateSolidBrush, CreateSolidBrush);
8101 const char *oleLibraryName =
"ole32.dll";
8103 FPL__WIN32_LOAD_LIBRARY(FPL__MODULE_WIN32, oleLibrary, oleLibraryName);
8104 wapi->ole.oleLibrary = oleLibrary;
8105 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, oleLibrary, oleLibraryName, &wapi->ole, fpl__win32_func_CoInitializeEx, CoInitializeEx);
8106 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, oleLibrary, oleLibraryName, &wapi->ole, fpl__win32_func_CoUninitialize, CoUninitialize);
8107 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, oleLibrary, oleLibraryName, &wapi->ole, fpl__win32_func_CoCreateInstance, CoCreateInstance);
8108 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, oleLibrary, oleLibraryName, &wapi->ole, fpl__win32_func_CoTaskMemFree, CoTaskMemFree);
8109 FPL__WIN32_GET_FUNCTION_ADDRESS(FPL__MODULE_WIN32, oleLibrary, oleLibraryName, &wapi->ole, fpl__win32_func_PropVariantClear, PropVariantClear);
8114 fpl__Win32UnloadApi(wapi);
8116 wapi->isValid = result;
8121#define FPL__WIN32_CLASSNAME L"FPLWindowClassW"
8122#define FPL__WIN32_UNNAMED_WINDOW L"Unnamed FPL Unicode Window"
8123#define FPL__WIN32_UNNAMED_CONSOLE L"Unnamed FPL Unicode Console"
8124#if defined(FPL_ARCH_X64)
8125# define fpl__win32_SetWindowLongPtr fpl__global__AppState->win32.winApi.user.SetWindowLongPtrW
8127# define fpl__win32_SetWindowLongPtr fpl__global__AppState->win32.winApi.user.SetWindowLongW
8129#define fpl__win32_SetWindowLong fpl__global__AppState->win32.winApi.user.SetWindowLongW
8130#define fpl__win32_GetWindowLong fpl__global__AppState->win32.winApi.user.GetWindowLongW
8132# define fpl__win32_LoadIcon fpl__global__AppState->win32.winApi.user.LoadIconW
8133# define fpl__win32_LoadCursor fpl__global__AppState->win32.winApi.user.LoadCursorW
8135# define fpl__win32_LoadIcon fpl__global__AppState->win32.winApi.user.LoadIconA
8136# define fpl__win32_LoadCursor fpl__global__AppState->win32.winApi.user.LoadCursorA
8141typedef struct fpl__Win32XInputState {
8142 fpl__GameControllerName deviceNames[XUSER_MAX_COUNT];
8143 fpl_b32 isConnected[XUSER_MAX_COUNT];
8144 fpl__Win32XInputApi xinputApi;
8145 LARGE_INTEGER lastDeviceSearchTime;
8146} fpl__Win32XInputState;
8148typedef struct fpl__Win32InitState {
8149 HINSTANCE appInstance;
8151} fpl__Win32InitState;
8153typedef struct fpl__Win32AppState {
8154 fpl__Win32XInputState xinput;
8155 fpl__Win32Api winApi;
8156} fpl__Win32AppState;
8158#if defined(FPL__ENABLE_WINDOW)
8159typedef struct fpl__Win32LastWindowInfo {
8160 WINDOWPLACEMENT placement;
8166} fpl__Win32LastWindowInfo;
8168typedef struct fpl__Win32WindowState {
8169 wchar_t windowClass[256];
8170 fpl__Win32LastWindowInfo lastFullscreenInfo;
8175 HBRUSH backgroundBrush;
8176 HCURSOR defaultCursor;
8180} fpl__Win32WindowState;
8190#if defined(FPL_SUBPLATFORM_POSIX)
8191# include <sys/types.h>
8192# include <sys/mman.h>
8193# include <sys/stat.h>
8194# include <sys/errno.h>
8195# include <sys/time.h>
8196# include <sys/utsname.h>
8206#if !defined(FPL_PLATFORM_ANDROID)
8207# define st_atime st_atim.tv_sec
8208# define st_mtime st_mtim.tv_sec
8209# define st_ctime st_ctim.tv_sec
8212#if defined(FPL_PLATFORM_LINUX)
8213# define fpl__lseek64 lseek64
8214# define fpl__off64_t off64_t
8216# define fpl__lseek64 lseek
8217# define fpl__off64_t off_t
8221#define FPL__POSIX_LOAD_LIBRARY_BREAK(mod, target, libName) \
8222 (target) = dlopen(libName, FPL__POSIX_DL_LOADTYPE); \
8223 if((target) == fpl_null) { \
8224 FPL__WARNING(mod, "Failed loading library '%s'", (libName)); \
8228#define FPL__POSIX_GET_FUNCTION_ADDRESS_OPTIONAL(mod, libHandle, libName, target, type, name) \
8229 (target)->name = (type *)dlsym(libHandle, #name)
8231#define FPL__POSIX_GET_FUNCTION_ADDRESS_BREAK(mod, libHandle, libName, target, type, name) \
8232 (target)->name = (type *)dlsym(libHandle, #name); \
8233 if ((target)->name == fpl_null) { \
8234 FPL__WARNING(mod, "Failed getting procedure address '%s' from library '%s'", #name, libName); \
8237#if !defined(FPL_NO_RUNTIME_LINKING)
8238# define FPL__POSIX_LOAD_LIBRARY FPL__POSIX_LOAD_LIBRARY_BREAK
8239# define FPL__POSIX_GET_FUNCTION_ADDRESS FPL__POSIX_GET_FUNCTION_ADDRESS_BREAK
8241# define FPL__POSIX_LOAD_LIBRARY(mod, target, libName)
8242# define FPL__POSIX_GET_FUNCTION_ADDRESS_OPTIONAL(mod, libHandle, libName, target, type, name) \
8243 (target)->name = name
8244# define FPL__POSIX_GET_FUNCTION_ADDRESS(mod, libHandle, libName, target, type, name) \
8245 (target)->name = name
8248#define FPL__FUNC_PTHREAD_pthread_self(name) pthread_t name(void)
8249typedef FPL__FUNC_PTHREAD_pthread_self(fpl__pthread_func_pthread_self);
8250#define FPL__FUNC_PTHREAD_pthread_setschedparam(name) int name(pthread_t thread, int policy, const struct sched_param *param)
8251typedef FPL__FUNC_PTHREAD_pthread_setschedparam(fpl__pthread_func_pthread_setschedparam);
8252#define FPL__FUNC_PTHREAD_pthread_getschedparam(name) int name(pthread_t thread, int *policy, struct sched_param *param)
8253typedef FPL__FUNC_PTHREAD_pthread_getschedparam(fpl__pthread_func_pthread_getschedparam);
8254#define FPL__FUNC_PTHREAD_pthread_setschedprio(name) int name(pthread_t thread, int prio)
8255typedef FPL__FUNC_PTHREAD_pthread_setschedprio(fpl__pthread_func_pthread_setschedprio);
8257#define FPL__FUNC_PTHREAD_pthread_attr_init(name) int name(pthread_attr_t *attr)
8258typedef FPL__FUNC_PTHREAD_pthread_attr_init(fpl__pthread_func_pthread_attr_init);
8259#define FPL__FUNC_PTHREAD_pthread_attr_getschedparam(name) int name(const pthread_attr_t *__restrict__ attr, struct sched_param *__restrict__ param)
8260typedef FPL__FUNC_PTHREAD_pthread_attr_getschedparam(fpl__pthread_func_pthread_attr_getschedparam);
8261#define FPL__FUNC_PTHREAD_pthread_attr_setschedparam(name) int name(pthread_attr_t *__restrict__ attr, const struct sched_param *__restrict__ param)
8262typedef FPL__FUNC_PTHREAD_pthread_attr_setschedparam(fpl__pthread_func_pthread_attr_setschedparam);
8263#define FPL__FUNC_PTHREAD_pthread_attr_setstacksize(name) int name(pthread_attr_t *attr, size_t stacksize)
8264typedef FPL__FUNC_PTHREAD_pthread_attr_setstacksize(fpl__pthread_func_pthread_attr_setstacksize);
8265#define FPL__FUNC_PTHREAD_pthread_attr_setdetachstate(name) int name(pthread_attr_t *attr, int detachstate);
8266typedef FPL__FUNC_PTHREAD_pthread_attr_setdetachstate(fpl__pthread_func_pthread_attr_setdetachstate);
8267#define FPL__FUNC_PTHREAD_pthread_attr_setschedpolicy(name) int name(pthread_attr_t *__attr, int __policy)
8268typedef FPL__FUNC_PTHREAD_pthread_attr_setschedpolicy(fpl__pthread_func_pthread_attr_setschedpolicy);
8270#define FPL__FUNC_PTHREAD_pthread_create(name) int name(pthread_t *, const pthread_attr_t *, void *(*__start_routine) (void *), void *)
8271typedef FPL__FUNC_PTHREAD_pthread_create(fpl__pthread_func_pthread_create);
8272#define FPL__FUNC_PTHREAD_pthread_kill(name) int name(pthread_t thread, int sig)
8273typedef FPL__FUNC_PTHREAD_pthread_kill(fpl__pthread_func_pthread_kill);
8274#define FPL__FUNC_PTHREAD_pthread_join(name) int name(pthread_t __th, void **retval)
8275typedef FPL__FUNC_PTHREAD_pthread_join(fpl__pthread_func_pthread_join);
8276#define FPL__FUNC_PTHREAD_pthread_exit(name) void name(void *__retval)
8277typedef FPL__FUNC_PTHREAD_pthread_exit(fpl__pthread_func_pthread_exit);
8278#define FPL__FUNC_PTHREAD_pthread_yield(name) int name(void)
8279typedef FPL__FUNC_PTHREAD_pthread_yield(fpl__pthread_func_pthread_yield);
8280#define FPL__FUNC_PTHREAD_pthread_timedjoin_np(name) int name(pthread_t thread, void **retval, const struct timespec *abstime)
8281typedef FPL__FUNC_PTHREAD_pthread_timedjoin_np(fpl__pthread_func_pthread_timedjoin_np);
8283#define FPL__FUNC_PTHREAD_pthread_mutex_init(name) int name(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
8284typedef FPL__FUNC_PTHREAD_pthread_mutex_init(fpl__pthread_func_pthread_mutex_init);
8285#define FPL__FUNC_PTHREAD_pthread_mutex_destroy(name) int name(pthread_mutex_t *mutex)
8286typedef FPL__FUNC_PTHREAD_pthread_mutex_destroy(fpl__pthread_func_pthread_mutex_destroy);
8287#define FPL__FUNC_PTHREAD_pthread_mutex_lock(name) int name(pthread_mutex_t *mutex)
8288typedef FPL__FUNC_PTHREAD_pthread_mutex_lock(fpl__pthread_func_pthread_mutex_lock);
8289#define FPL__FUNC_PTHREAD_pthread_mutex_trylock(name) int name(pthread_mutex_t *mutex)
8290typedef FPL__FUNC_PTHREAD_pthread_mutex_trylock(fpl__pthread_func_pthread_mutex_trylock);
8291#define FPL__FUNC_PTHREAD_pthread_mutex_unlock(name) int name(pthread_mutex_t *mutex)
8292typedef FPL__FUNC_PTHREAD_pthread_mutex_unlock(fpl__pthread_func_pthread_mutex_unlock);
8294#define FPL__FUNC_PTHREAD_pthread_cond_init(name) int name(pthread_cond_t *cond, const pthread_condattr_t *attr)
8295typedef FPL__FUNC_PTHREAD_pthread_cond_init(fpl__pthread_func_pthread_cond_init);
8296#define FPL__FUNC_PTHREAD_pthread_cond_destroy(name) int name(pthread_cond_t *cond)
8297typedef FPL__FUNC_PTHREAD_pthread_cond_destroy(fpl__pthread_func_pthread_cond_destroy);
8298#define FPL__FUNC_PTHREAD_pthread_cond_timedwait(name) int name(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime)
8299typedef FPL__FUNC_PTHREAD_pthread_cond_timedwait(fpl__pthread_func_pthread_cond_timedwait);
8300#define FPL__FUNC_PTHREAD_pthread_cond_wait(name) int name(pthread_cond_t *cond, pthread_mutex_t *mutex)
8301typedef FPL__FUNC_PTHREAD_pthread_cond_wait(fpl__pthread_func_pthread_cond_wait);
8302#define FPL__FUNC_PTHREAD_pthread_cond_broadcast(name) int name(pthread_cond_t *cond)
8303typedef FPL__FUNC_PTHREAD_pthread_cond_broadcast(fpl__pthread_func_pthread_cond_broadcast);
8304#define FPL__FUNC_PTHREAD_pthread_cond_signal(name) int name(pthread_cond_t *cond)
8305typedef FPL__FUNC_PTHREAD_pthread_cond_signal(fpl__pthread_func_pthread_cond_signal);
8307#define FPL__FUNC_PTHREAD_sem_init(name) int name(sem_t *__sem, int __pshared, unsigned int __value)
8308typedef FPL__FUNC_PTHREAD_sem_init(fpl__pthread_func_sem_init);
8309#define FPL__FUNC_PTHREAD_sem_destroy(name) int name(sem_t *__sem)
8310typedef FPL__FUNC_PTHREAD_sem_destroy(fpl__pthread_func_sem_destroy);
8311#define FPL__FUNC_PTHREAD_sem_wait(name) int name(sem_t *__sem)
8312typedef FPL__FUNC_PTHREAD_sem_wait(fpl__pthread_func_sem_wait);
8313#define FPL__FUNC_PTHREAD_sem_timedwait(name) int name(sem_t *__restrict __sem, const struct timespec *__restrict __abstime)
8314typedef FPL__FUNC_PTHREAD_sem_timedwait(fpl__pthread_func_sem_timedwait);
8315#define FPL__FUNC_PTHREAD_sem_trywait(name) int name(sem_t *__sem)
8316typedef FPL__FUNC_PTHREAD_sem_trywait(fpl__pthread_func_sem_trywait);
8317#define FPL__FUNC_PTHREAD_sem_post(name) int name(sem_t *__sem)
8318typedef FPL__FUNC_PTHREAD_sem_post(fpl__pthread_func_sem_post);
8319#define FPL__FUNC_PTHREAD_sem_getvalue(name) int name(sem_t *__restrict __sem, int *__restrict __sval)
8320typedef FPL__FUNC_PTHREAD_sem_getvalue(fpl__pthread_func_sem_getvalue);
8322typedef struct fpl__PThreadApi {
8326 fpl__pthread_func_pthread_self *pthread_self;
8327 fpl__pthread_func_pthread_setschedparam *pthread_setschedparam;
8328 fpl__pthread_func_pthread_getschedparam *pthread_getschedparam;
8329 fpl__pthread_func_pthread_setschedprio *pthread_setschedprio;
8331 fpl__pthread_func_pthread_create *pthread_create;
8332 fpl__pthread_func_pthread_kill *pthread_kill;
8333 fpl__pthread_func_pthread_join *pthread_join;
8334 fpl__pthread_func_pthread_exit *pthread_exit;
8335 fpl__pthread_func_pthread_yield *pthread_yield;
8336 fpl__pthread_func_pthread_timedjoin_np *pthread_timedjoin_np;
8339 fpl__pthread_func_pthread_attr_init *pthread_attr_init;
8340 fpl__pthread_func_pthread_attr_getschedparam *pthread_attr_getschedparam;
8341 fpl__pthread_func_pthread_attr_setschedparam *pthread_attr_setschedparam;
8342 fpl__pthread_func_pthread_attr_setstacksize *pthread_attr_setstacksize;
8343 fpl__pthread_func_pthread_attr_setdetachstate *pthread_attr_setdetachstate;
8344 fpl__pthread_func_pthread_attr_setschedpolicy *pthread_attr_setschedpolicy;
8347 fpl__pthread_func_pthread_mutex_init *pthread_mutex_init;
8348 fpl__pthread_func_pthread_mutex_destroy *pthread_mutex_destroy;
8349 fpl__pthread_func_pthread_mutex_lock *pthread_mutex_lock;
8350 fpl__pthread_func_pthread_mutex_trylock *pthread_mutex_trylock;
8351 fpl__pthread_func_pthread_mutex_unlock *pthread_mutex_unlock;
8354 fpl__pthread_func_pthread_cond_init *pthread_cond_init;
8355 fpl__pthread_func_pthread_cond_destroy *pthread_cond_destroy;
8356 fpl__pthread_func_pthread_cond_timedwait *pthread_cond_timedwait;
8357 fpl__pthread_func_pthread_cond_wait *pthread_cond_wait;
8358 fpl__pthread_func_pthread_cond_broadcast *pthread_cond_broadcast;
8359 fpl__pthread_func_pthread_cond_signal *pthread_cond_signal;
8362 fpl__pthread_func_sem_init *sem_init;
8363 fpl__pthread_func_sem_destroy *sem_destroy;
8364 fpl__pthread_func_sem_wait *sem_wait;
8365 fpl__pthread_func_sem_timedwait *sem_timedwait;
8366 fpl__pthread_func_sem_trywait *sem_trywait;
8367 fpl__pthread_func_sem_post *sem_post;
8368 fpl__pthread_func_sem_getvalue *sem_getvalue;
8371#define FPL__POSIX_DL_LOADTYPE RTLD_NOW
8373fpl_internal void fpl__PThreadUnloadApi(fpl__PThreadApi *pthreadApi) {
8375 if (pthreadApi->libHandle !=
fpl_null) {
8376 dlclose(pthreadApi->libHandle);
8381fpl_internal bool fpl__PThreadLoadApi(fpl__PThreadApi *pthreadApi) {
8382 const char *libpthreadFileNames[] = {
8386 bool result =
false;
8387 for (uint32_t index = 0; index <
fplArrayCount(libpthreadFileNames); ++index) {
8388 const char *libName = libpthreadFileNames[index];
8392 FPL__POSIX_LOAD_LIBRARY(FPL__MODULE_PTHREAD, libHandle, libName);
8395 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_PTHREAD, libHandle, libName, pthreadApi, fpl__pthread_func_pthread_self, pthread_self);
8396 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_PTHREAD, libHandle, libName, pthreadApi, fpl__pthread_func_pthread_setschedparam, pthread_setschedparam);
8397 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_PTHREAD, libHandle, libName, pthreadApi, fpl__pthread_func_pthread_getschedparam, pthread_getschedparam);
8398 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_PTHREAD, libHandle, libName, pthreadApi, fpl__pthread_func_pthread_setschedprio, pthread_setschedprio);
8400 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_PTHREAD, libHandle, libName, pthreadApi, fpl__pthread_func_pthread_create, pthread_create);
8401 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_PTHREAD, libHandle, libName, pthreadApi, fpl__pthread_func_pthread_kill, pthread_kill);
8402 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_PTHREAD, libHandle, libName, pthreadApi, fpl__pthread_func_pthread_join, pthread_join);
8403 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_PTHREAD, libHandle, libName, pthreadApi, fpl__pthread_func_pthread_exit, pthread_exit);
8404 FPL__POSIX_GET_FUNCTION_ADDRESS_OPTIONAL(FPL__MODULE_PTHREAD, libHandle, libName, pthreadApi, fpl__pthread_func_pthread_yield, pthread_yield);
8405 FPL__POSIX_GET_FUNCTION_ADDRESS_OPTIONAL(FPL__MODULE_PTHREAD, libHandle, libName, pthreadApi, fpl__pthread_func_pthread_timedjoin_np, pthread_timedjoin_np);
8408 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_PTHREAD, libHandle, libName, pthreadApi, fpl__pthread_func_pthread_attr_init, pthread_attr_init);
8409 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_PTHREAD, libHandle, libName, pthreadApi, fpl__pthread_func_pthread_attr_getschedparam, pthread_attr_getschedparam);
8410 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_PTHREAD, libHandle, libName, pthreadApi, fpl__pthread_func_pthread_attr_setschedparam, pthread_attr_setschedparam);
8411 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_PTHREAD, libHandle, libName, pthreadApi, fpl__pthread_func_pthread_attr_setstacksize, pthread_attr_setstacksize);
8412 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_PTHREAD, libHandle, libName, pthreadApi, fpl__pthread_func_pthread_attr_setdetachstate, pthread_attr_setdetachstate);
8413 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_PTHREAD, libHandle, libName, pthreadApi, fpl__pthread_func_pthread_attr_setschedpolicy, pthread_attr_setschedpolicy);
8416 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_PTHREAD, libHandle, libName, pthreadApi, fpl__pthread_func_pthread_mutex_init, pthread_mutex_init);
8417 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_PTHREAD, libHandle, libName, pthreadApi, fpl__pthread_func_pthread_mutex_destroy, pthread_mutex_destroy);
8418 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_PTHREAD, libHandle, libName, pthreadApi, fpl__pthread_func_pthread_mutex_lock, pthread_mutex_lock);
8419 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_PTHREAD, libHandle, libName, pthreadApi, fpl__pthread_func_pthread_mutex_trylock, pthread_mutex_trylock);
8420 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_PTHREAD, libHandle, libName, pthreadApi, fpl__pthread_func_pthread_mutex_unlock, pthread_mutex_unlock);
8423 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_PTHREAD, libHandle, libName, pthreadApi, fpl__pthread_func_pthread_cond_init, pthread_cond_init);
8424 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_PTHREAD, libHandle, libName, pthreadApi, fpl__pthread_func_pthread_cond_destroy, pthread_cond_destroy);
8425 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_PTHREAD, libHandle, libName, pthreadApi, fpl__pthread_func_pthread_cond_timedwait, pthread_cond_timedwait);
8426 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_PTHREAD, libHandle, libName, pthreadApi, fpl__pthread_func_pthread_cond_wait, pthread_cond_wait);
8427 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_PTHREAD, libHandle, libName, pthreadApi, fpl__pthread_func_pthread_cond_broadcast, pthread_cond_broadcast);
8428 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_PTHREAD, libHandle, libName, pthreadApi, fpl__pthread_func_pthread_cond_signal, pthread_cond_signal);
8431 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_PTHREAD, libHandle, libName, pthreadApi, fpl__pthread_func_sem_init, sem_init);
8432 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_PTHREAD, libHandle, libName, pthreadApi, fpl__pthread_func_sem_destroy, sem_destroy);
8433 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_PTHREAD, libHandle, libName, pthreadApi, fpl__pthread_func_sem_wait, sem_wait);
8434 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_PTHREAD, libHandle, libName, pthreadApi, fpl__pthread_func_sem_timedwait, sem_timedwait);
8435 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_PTHREAD, libHandle, libName, pthreadApi, fpl__pthread_func_sem_trywait, sem_trywait);
8436 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_PTHREAD, libHandle, libName, pthreadApi, fpl__pthread_func_sem_post, sem_post);
8437 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_PTHREAD, libHandle, libName, pthreadApi, fpl__pthread_func_sem_getvalue, sem_getvalue);
8439 pthreadApi->libHandle = libHandle;
8445 fpl__PThreadUnloadApi(pthreadApi);
8450typedef struct fpl__PosixInitState {
8452} fpl__PosixInitState;
8454typedef struct fpl__PosixAppState {
8455 fpl__PThreadApi pthreadApi;
8456} fpl__PosixAppState;
8464#if defined(FPL_PLATFORM_LINUX)
8465typedef struct fpl__LinuxInitState {
8467} fpl__LinuxInitState;
8469#if defined(FPL__ENABLE_WINDOW)
8470#define FPL__LINUX_MAX_GAME_CONTROLLER_COUNT 4
8471typedef struct fpl__LinuxGameController {
8472 char deviceName[512 + 1];
8476 uint8_t buttonCount;
8478} fpl__LinuxGameController;
8480typedef struct fpl__LinuxGameControllersState {
8481 fpl__LinuxGameController controllers[FPL__LINUX_MAX_GAME_CONTROLLER_COUNT];
8482 uint64_t lastCheckTime;
8483} fpl__LinuxGameControllersState;
8486typedef struct fpl__LinuxAppState {
8487#if defined(FPL__ENABLE_WINDOW)
8488 fpl__LinuxGameControllersState controllersState;
8491} fpl__LinuxAppState;
8494#if defined(FPL__ENABLE_WINDOW)
8495fpl_internal void fpl__LinuxFreeGameControllers(fpl__LinuxGameControllersState *controllersState);
8496fpl_internal void fpl__LinuxPollGameControllers(
const fplSettings *settings, fpl__LinuxGameControllersState *controllersState,
const bool useEvents);
8506#if defined(FPL_PLATFORM_UNIX)
8507typedef struct fpl__UnixInitState {
8509} fpl__UnixInitState;
8511typedef struct fpl__UnixAppState {
8521#if defined(FPL_SUBPLATFORM_X11)
8523#include <X11/keysym.h>
8528#define FPL__FUNC_X11_XFree(name) int name(void *data)
8529typedef FPL__FUNC_X11_XFree(fpl__func_x11_XFree);
8530#define FPL__FUNC_X11_XFlush(name) int name(Display *display)
8531typedef FPL__FUNC_X11_XFlush(fpl__func_x11_XFlush);
8532#define FPL__FUNC_X11_XOpenDisplay(name) Display *name(char *display_name)
8533typedef FPL__FUNC_X11_XOpenDisplay(fpl__func_x11_XOpenDisplay);
8534#define FPL__FUNC_X11_XCloseDisplay(name) int name(Display *display)
8535typedef FPL__FUNC_X11_XCloseDisplay(fpl__func_x11_XCloseDisplay);
8536#define FPL__FUNC_X11_XDefaultScreen(name) int name(Display *display)
8537typedef FPL__FUNC_X11_XDefaultScreen(fpl__func_x11_XDefaultScreen);
8538#define FPL__FUNC_X11_XRootWindow(name) Window name(Display *display, int screen_number)
8539typedef FPL__FUNC_X11_XRootWindow(fpl__func_x11_XRootWindow);
8540#define FPL__FUNC_X11_XCreateWindow(name) Window name(Display *display, Window parent, int x, int y, unsigned int width, unsigned int height, unsigned int border_width, int depth, unsigned int clazz, Visual *visual, unsigned long valuemask, XSetWindowAttributes *attributes)
8541typedef FPL__FUNC_X11_XCreateWindow(fpl__func_x11_XCreateWindow);
8542#define FPL__FUNC_X11_XDestroyWindow(name) int name(Display *display, Window w)
8543typedef FPL__FUNC_X11_XDestroyWindow(fpl__func_x11_XDestroyWindow);
8544#define FPL__FUNC_X11_XCreateColormap(name) Colormap name(Display *display, Window w, Visual *visual, int alloc)
8545typedef FPL__FUNC_X11_XCreateColormap(fpl__func_x11_XCreateColormap);
8546#define FPL__FUNC_X11_XDefaultColormap(name) Colormap name(Display *display, int screen_number)
8547typedef FPL__FUNC_X11_XDefaultColormap(fpl__func_x11_XDefaultColormap);
8548#define FPL__FUNC_X11_XFreeColormap(name) int name(Display *display, Colormap colormap)
8549typedef FPL__FUNC_X11_XFreeColormap(fpl__func_x11_XFreeColormap);
8550#define FPL__FUNC_X11_XMapWindow(name) int name(Display *display, Window w)
8551typedef FPL__FUNC_X11_XMapWindow(fpl__func_x11_XMapWindow);
8552#define FPL__FUNC_X11_XUnmapWindow(name) int name(Display *display, Window w)
8553typedef FPL__FUNC_X11_XUnmapWindow(fpl__func_x11_XUnmapWindow);
8554#define FPL__FUNC_X11_XStoreName(name) int name(Display *display, Window w, _Xconst char *window_name)
8555typedef FPL__FUNC_X11_XStoreName(fpl__func_x11_XStoreName);
8556#define FPL__FUNC_X11_XDefaultVisual(name) Visual *name(Display *display, int screen_number)
8557typedef FPL__FUNC_X11_XDefaultVisual(fpl__func_x11_XDefaultVisual);
8558#define FPL__FUNC_X11_XDefaultDepth(name) int name(Display *display, int screen_number)
8559typedef FPL__FUNC_X11_XDefaultDepth(fpl__func_x11_XDefaultDepth);
8560#define FPL__FUNC_X11_XInternAtom(name) Atom name(Display *display, const char *atom_name, Bool only_if_exists)
8561typedef FPL__FUNC_X11_XInternAtom(fpl__func_x11_XInternAtom);
8562#define FPL__FUNC_X11_XSetWMProtocols(name) Status name(Display *display, Window w, Atom *protocols, int count)
8563typedef FPL__FUNC_X11_XSetWMProtocols(fpl__func_x11_XSetWMProtocols);
8564#define FPL__FUNC_X11_XPending(name) int name(Display *display)
8565typedef FPL__FUNC_X11_XPending(fpl__func_x11_XPending);
8566#define FPL__FUNC_X11_XSync(name) int name(Display *display, Bool discard)
8567typedef FPL__FUNC_X11_XSync(fpl__func_x11_XSync);
8568#define FPL__FUNC_X11_XNextEvent(name) int name(Display *display, XEvent *event_return)
8569typedef FPL__FUNC_X11_XNextEvent(fpl__func_x11_XNextEvent);
8570#define FPL__FUNC_X11_XPeekEvent(name) int name(Display *display, XEvent *event_return)
8571typedef FPL__FUNC_X11_XPeekEvent(fpl__func_x11_XPeekEvent);
8572#define FPL__FUNC_X11_XEventsQueued(name) int name(Display *display, int mode)
8573typedef FPL__FUNC_X11_XEventsQueued(fpl__func_x11_XEventsQueued);
8574#define FPL__FUNC_X11_XGetWindowAttributes(name) Status name(Display *display, Window w, XWindowAttributes *window_attributes_return)
8575typedef FPL__FUNC_X11_XGetWindowAttributes(fpl__func_x11_XGetWindowAttributes);
8576#define FPL__FUNC_X11_XResizeWindow(name) int name(Display *display, Window w, unsigned int width, unsigned int height)
8577typedef FPL__FUNC_X11_XResizeWindow(fpl__func_x11_XResizeWindow);
8578#define FPL__FUNC_X11_XMoveWindow(name) int name(Display *display, Window w, int x, int y)
8579typedef FPL__FUNC_X11_XMoveWindow(fpl__func_x11_XMoveWindow);
8580#define FPL__FUNC_X11_XGetKeyboardMapping(name) KeySym *name(Display *display, KeyCode first_keycode, int keycode_count, int *keysyms_per_keycode_return)
8581typedef FPL__FUNC_X11_XGetKeyboardMapping(fpl__func_x11_XGetKeyboardMapping);
8582#define FPL__FUNC_X11_XLookupString(name) int name(XKeyEvent* event_struct, char* buffer_return, int bytes_buffer, KeySym* keysym_return, XComposeStatus* status_in_out)
8583typedef FPL__FUNC_X11_XLookupString(fpl__func_x11_XLookupString);
8584#define FPL__FUNC_X11_XSendEvent(name) Status name(Display *display, Window w, Bool propagate, long event_mask, XEvent *event_send)
8585typedef FPL__FUNC_X11_XSendEvent(fpl__func_x11_XSendEvent);
8586#define FPL__FUNC_X11_XMatchVisualInfo(name) Status name(Display* display, int screen, int depth, int clazz, XVisualInfo* vinfo_return)
8587typedef FPL__FUNC_X11_XMatchVisualInfo(fpl__func_x11_XMatchVisualInfo);
8588#define FPL__FUNC_X11_XCreateGC(name) GC name(Display* display, Drawable d, unsigned long valuemask, XGCValues* values)
8589typedef FPL__FUNC_X11_XCreateGC(fpl__func_x11_XCreateGC);
8590#define FPL__FUNC_X11_XGetImage(name) XImage *name(Display* display, Drawable d, int x, int y, unsigned int width, unsigned int height, unsigned long plane_mask, int format)
8591typedef FPL__FUNC_X11_XGetImage(fpl__func_x11_XGetImage);
8592#define FPL__FUNC_X11_XCreateImage(name) XImage *name(Display *display, Visual *visual, unsigned int depth, int format, int offset, char *data, unsigned int width, unsigned int height, int bitmap_pad, int bytes_per_line)
8593typedef FPL__FUNC_X11_XCreateImage(fpl__func_x11_XCreateImage);
8594#define FPL__FUNC_X11_XPutImage(name) int name(Display *display, Drawable d, GC gc, XImage *image, int src_x, int src_y, int dest_x, int dest_y, unsigned int width, unsigned int height)
8595typedef FPL__FUNC_X11_XPutImage(fpl__func_x11_XPutImage);
8596#define FPL__FUNC_X11_XMapRaised(name) int name(Display *display, Window w)
8597typedef FPL__FUNC_X11_XMapRaised(fpl__func_x11_XMapRaised);
8598#define FPL__FUNC_X11_XCreatePixmap(name) Pixmap name(Display * display, Drawable d, unsigned int width, unsigned int height, unsigned int depth)
8599typedef FPL__FUNC_X11_XCreatePixmap(fpl__func_x11_XCreatePixmap);
8600#define FPL__FUNC_X11_XSelectInput(name) int name(Display * display, Window w, long eventMask)
8601typedef FPL__FUNC_X11_XSelectInput(fpl__func_x11_XSelectInput);
8602#define FPL__FUNC_X11_XGetWindowProperty(name) int name(Display* display, Window w, Atom prop, long long_offset, long long_length, Bool del, Atom req_type, Atom* actual_type_return, int* actual_format_return, unsigned long* nitems_return, unsigned long* bytes_after_return, unsigned char** prop_return)
8603typedef FPL__FUNC_X11_XGetWindowProperty(fpl__func_x11_XGetWindowProperty);
8604#define FPL__FUNC_X11_XChangeProperty(name) int name(Display* display, Window w, Atom property, Atom type, int format, int mode, _Xconst unsigned char* data, int nelements)
8605typedef FPL__FUNC_X11_XChangeProperty(fpl__func_x11_XChangeProperty);
8606#define FPL__FUNC_X11_XDeleteProperty(name) int name(Display* display, Window w,Atom prop)
8607typedef FPL__FUNC_X11_XDeleteProperty(fpl__func_x11_XDeleteProperty);
8608#define FPL__FUNC_X11_XStringListToTextProperty(name) Status name(char** list, int count, XTextProperty* text_prop_return)
8609typedef FPL__FUNC_X11_XStringListToTextProperty(fpl__func_x11_XStringListToTextProperty);
8610#define FPL__FUNC_X11_XSetWMIconName(name) void name(Display* display, Window w, XTextProperty *text_prop)
8611typedef FPL__FUNC_X11_XSetWMIconName(fpl__func_x11_XSetWMIconName);
8612#define FPL__FUNC_X11_XSetWMName(name) void name(Display* display, Window w, XTextProperty *text_prop)
8613typedef FPL__FUNC_X11_XSetWMName(fpl__func_x11_XSetWMName);
8614#define FPL__FUNC_X11_XQueryKeymap(name) int name(Display* display, char [32])
8615typedef FPL__FUNC_X11_XQueryKeymap(fpl__func_x11_XQueryKeymap);
8616#define FPL__FUNC_X11_XQueryPointer(name) Bool name(Display* display, Window w, Window* root_return, Window* child_return, int* root_x_return, int* root_y_return, int* win_x_return, int* win_y_return, unsigned int* mask_return)
8617typedef FPL__FUNC_X11_XQueryPointer(fpl__func_x11_XQueryPointer);
8618#define FPL__FUNC_X11_XConvertSelection(name) int name(Display *display, Atom selection, Atom target, Atom property, Window requestor, Time time)
8619typedef FPL__FUNC_X11_XConvertSelection(fpl__func_x11_XConvertSelection);
8620#define FPL__FUNC_X11_XInitThreads(name) Status name(void)
8621typedef FPL__FUNC_X11_XInitThreads(fpl__func_x11_XInitThreads);
8622#define FPL__FUNC_X11_XSetErrorHandler(name) XErrorHandler name(XErrorHandler *handler)
8623typedef FPL__FUNC_X11_XSetErrorHandler(fpl__func_x11_XSetErrorHandler);
8625typedef struct fpl__X11Api {
8627 fpl__func_x11_XFlush *XFlush;
8628 fpl__func_x11_XFree *XFree;
8629 fpl__func_x11_XOpenDisplay *XOpenDisplay;
8630 fpl__func_x11_XCloseDisplay *XCloseDisplay;
8631 fpl__func_x11_XDefaultScreen *XDefaultScreen;
8632 fpl__func_x11_XRootWindow *XRootWindow;
8633 fpl__func_x11_XCreateWindow *XCreateWindow;
8634 fpl__func_x11_XDestroyWindow *XDestroyWindow;
8635 fpl__func_x11_XCreateColormap *XCreateColormap;
8636 fpl__func_x11_XFreeColormap *XFreeColormap;
8637 fpl__func_x11_XDefaultColormap *XDefaultColormap;
8638 fpl__func_x11_XMapWindow *XMapWindow;
8639 fpl__func_x11_XUnmapWindow *XUnmapWindow;
8640 fpl__func_x11_XStoreName *XStoreName;
8641 fpl__func_x11_XDefaultVisual *XDefaultVisual;
8642 fpl__func_x11_XDefaultDepth *XDefaultDepth;
8643 fpl__func_x11_XInternAtom *XInternAtom;
8644 fpl__func_x11_XSetWMProtocols *XSetWMProtocols;
8645 fpl__func_x11_XPending *XPending;
8646 fpl__func_x11_XSync *XSync;
8647 fpl__func_x11_XNextEvent *XNextEvent;
8648 fpl__func_x11_XPeekEvent *XPeekEvent;
8649 fpl__func_x11_XEventsQueued *XEventsQueued;
8650 fpl__func_x11_XGetWindowAttributes *XGetWindowAttributes;
8651 fpl__func_x11_XResizeWindow *XResizeWindow;
8652 fpl__func_x11_XMoveWindow *XMoveWindow;
8653 fpl__func_x11_XGetKeyboardMapping *XGetKeyboardMapping;
8654 fpl__func_x11_XLookupString *XLookupString;
8655 fpl__func_x11_XSendEvent *XSendEvent;
8656 fpl__func_x11_XMatchVisualInfo *XMatchVisualInfo;
8657 fpl__func_x11_XCreateGC *XCreateGC;
8658 fpl__func_x11_XGetImage *XGetImage;
8659 fpl__func_x11_XPutImage *XPutImage;
8660 fpl__func_x11_XMapRaised *XMapRaised;
8661 fpl__func_x11_XCreateImage *XCreateImage;
8662 fpl__func_x11_XCreatePixmap *XCreatePixmap;
8663 fpl__func_x11_XSelectInput *XSelectInput;
8664 fpl__func_x11_XGetWindowProperty *XGetWindowProperty;
8665 fpl__func_x11_XChangeProperty *XChangeProperty;
8666 fpl__func_x11_XDeleteProperty *XDeleteProperty;
8667 fpl__func_x11_XStringListToTextProperty *XStringListToTextProperty;
8668 fpl__func_x11_XSetWMIconName *XSetWMIconName;
8669 fpl__func_x11_XSetWMName *XSetWMName;
8670 fpl__func_x11_XQueryKeymap *XQueryKeymap;
8671 fpl__func_x11_XQueryPointer *XQueryPointer;
8672 fpl__func_x11_XConvertSelection *XConvertSelection;
8673 fpl__func_x11_XInitThreads *XInitThreads;
8674 fpl__func_x11_XSetErrorHandler *XSetErrorHandler;
8677fpl_internal void fpl__UnloadX11Api(fpl__X11Api *x11Api) {
8679 if (x11Api->libHandle !=
fpl_null) {
8680 dlclose(x11Api->libHandle);
8685fpl_internal bool fpl__LoadX11Api(fpl__X11Api *x11Api) {
8687 const char *libFileNames[] = {
8693 bool result =
false;
8694 for (uint32_t index = 0; index <
fplArrayCount(libFileNames); ++index) {
8695 const char *libName = libFileNames[index];
8699 FPL__POSIX_LOAD_LIBRARY(FPL__MODULE_X11, libHandle, libName);
8700 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XFlush, XFlush);
8701 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XFree, XFree);
8702 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XOpenDisplay, XOpenDisplay);
8703 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XCloseDisplay, XCloseDisplay);
8704 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XDefaultScreen, XDefaultScreen);
8705 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XRootWindow, XRootWindow);
8706 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XCreateWindow, XCreateWindow);
8707 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XDestroyWindow, XDestroyWindow);
8708 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XCreateColormap, XCreateColormap);
8709 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XFreeColormap, XFreeColormap);
8710 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XDefaultColormap, XDefaultColormap);
8711 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XMapWindow, XMapWindow);
8712 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XUnmapWindow, XUnmapWindow);
8713 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XStoreName, XStoreName);
8714 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XDefaultVisual, XDefaultVisual);
8715 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XDefaultDepth, XDefaultDepth);
8716 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XInternAtom, XInternAtom);
8717 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XSetWMProtocols, XSetWMProtocols);
8718 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XPending, XPending);
8719 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XSync, XSync);
8720 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XNextEvent, XNextEvent);
8721 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XPeekEvent, XPeekEvent);
8722 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XEventsQueued, XEventsQueued);
8723 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XGetWindowAttributes, XGetWindowAttributes);
8724 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XResizeWindow, XResizeWindow);
8725 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XMoveWindow, XMoveWindow);
8726 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XGetKeyboardMapping, XGetKeyboardMapping);
8727 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XLookupString, XLookupString);
8728 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XSendEvent, XSendEvent);
8729 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XMatchVisualInfo, XMatchVisualInfo);
8730 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XCreateGC, XCreateGC);
8731 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XGetImage, XGetImage);
8732 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XPutImage, XPutImage);
8733 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XMapRaised, XMapRaised);
8734 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XCreateImage, XCreateImage);
8735 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XCreatePixmap, XCreatePixmap);
8736 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XSelectInput, XSelectInput);
8737 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XGetWindowProperty, XGetWindowProperty);
8738 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XChangeProperty, XChangeProperty);
8739 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XDeleteProperty, XDeleteProperty);
8740 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XStringListToTextProperty, XStringListToTextProperty);
8741 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XSetWMIconName, XSetWMIconName);
8742 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XSetWMName, XSetWMName);
8743 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XQueryKeymap, XQueryKeymap);
8744 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XQueryPointer, XQueryPointer);
8745 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XConvertSelection, XConvertSelection);
8746 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XInitThreads, XInitThreads);
8747 FPL__POSIX_GET_FUNCTION_ADDRESS(FPL__MODULE_X11, libHandle, libName, x11Api, fpl__func_x11_XSetErrorHandler, XSetErrorHandler);
8748 x11Api->libHandle = libHandle;
8754 fpl__UnloadX11Api(x11Api);
8759typedef struct fpl__X11SubplatformState {
8761} fpl__X11SubplatformState;
8763typedef struct fpl__X11WindowStateInfo {
8768} fpl__X11WindowStateInfo;
8770typedef struct fpl__X11Xdnd {
8776#define FPL__FUNC_X11_ErrorHandlerCallback(name) int name(Display *display, XErrorEvent *ev)
8777typedef FPL__FUNC_X11_ErrorHandlerCallback(fpl__func_X11ErrorHandlerCallback);
8779typedef struct fpl__X11WindowState {
8780 fpl__X11WindowStateInfo lastWindowStateInfo;
8783 fpl__func_X11ErrorHandlerCallback *lastErrorHandler;
8789 Atom wmDeleteWindow;
8793 Atom netWMStateFocused;
8794 Atom netWMStateFullscreen;
8795 Atom netWMStateHidden;
8796 Atom netWMStateMaximizedVert;
8797 Atom netWMStateMaximizedHorz;
8809 Atom xdndActionCopy;
8817} fpl__X11WindowState;
8819#define FPL__XDND_VERSION 5
8831#if !defined(FPL__PLATFORM_STATES_DEFINED)
8832#define FPL__PLATFORM_STATES_DEFINED
8836typedef struct fpl__PlatformInitSettings {
8838} fpl__PlatformInitSettings;
8840typedef struct fpl__PlatformInitState {
8841#if defined(FPL_SUBPLATFORM_POSIX)
8842 fpl__PosixInitState posix;
8845 fpl__PlatformInitSettings initSettings;
8850# if defined(FPL_PLATFORM_WINDOWS)
8851 fpl__Win32InitState win32;
8852# elif defined(FPL_PLATFORM_LINUX)
8853 fpl__LinuxInitState plinux;
8854# elif defined(FPL_PLATFORM_UNIX)
8855 fpl__UnixInitState punix;
8858} fpl__PlatformInitState;
8861#if defined(FPL__ENABLE_WINDOW)
8862#define FPL__MAX_EVENT_COUNT 32768
8863typedef struct fpl__EventQueue {
8865 fplEvent events[FPL__MAX_EVENT_COUNT];
8870typedef struct fpl__PlatformWindowState {
8871 fpl__EventQueue eventQueue;
8874 uint64_t keyPressTimes[256];
8878#if defined(FPL_PLATFORM_WINDOWS)
8879 fpl__Win32WindowState win32;
8881#if defined(FPL_SUBPLATFORM_X11)
8882 fpl__X11WindowState x11;
8884} fpl__PlatformWindowState;
8887#if defined(FPL__ENABLE_VIDEO)
8888typedef struct fpl__PlatformVideoState {
8891} fpl__PlatformVideoState;
8894#if defined(FPL__ENABLE_AUDIO)
8895typedef struct fpl__PlatformAudioState {
8898} fpl__PlatformAudioState;
8904typedef struct fpl__PlatformAppState fpl__PlatformAppState;
8905struct fpl__PlatformAppState {
8907#if defined(FPL_SUBPLATFORM_POSIX)
8908 fpl__PosixAppState posix;
8910#if defined(FPL_SUBPLATFORM_X11)
8911 fpl__X11SubplatformState x11;
8915#if defined(FPL__ENABLE_WINDOW)
8916 fpl__PlatformWindowState window;
8918#if defined(FPL__ENABLE_VIDEO)
8919 fpl__PlatformVideoState video;
8921#if defined(FPL__ENABLE_AUDIO)
8922 fpl__PlatformAudioState audio;
8932# if defined(FPL_PLATFORM_WINDOWS)
8933 fpl__Win32AppState win32;
8934# elif defined(FPL_PLATFORM_LINUX)
8935 fpl__LinuxAppState plinux;
8936# elif defined(FPL_PLATFORM_UNIX)
8937 fpl__UnixAppState plinux;
8945#if defined(FPL__ENABLE_WINDOW)
8946fpl_internal fplKey fpl__GetMappedKey(
const fpl__PlatformWindowState *windowState,
const uint64_t keyCode) {
8949 result = windowState->keyMap[keyCode];
8951 result = fplKey_None;
8956 fpl__PlatformAppState *appState = fpl__global__AppState;
8958 fpl__EventQueue *eventQueue = &appState->window.eventQueue;
8960 uint32_t eventCount = eventQueue->pollIndex;
8961 eventQueue->pollIndex = 0;
8962 for (
size_t eventIndex = 0; eventIndex < eventCount; ++eventIndex) {
8963 fplEvent *ev = &eventQueue->events[eventIndex];
8969 eventQueue->pushCount = 0;