first commit
This commit is contained in:
86
inc/hgl/platform/os/Android.h
Normal file
86
inc/hgl/platform/os/Android.h
Normal file
@@ -0,0 +1,86 @@
|
||||
#ifndef HGL_OS_ANDROID_INCLUDE
|
||||
#define HGL_OS_ANDROID_INCLUDE
|
||||
|
||||
#include<limits.h>
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
using u32char =char32_t;
|
||||
using u16char =char16_t;
|
||||
using os_char =char;
|
||||
#define to_oschar to_u8
|
||||
#define OS_TEXT(str) u8##str
|
||||
#define U8_TEXT(str) u8##str
|
||||
#define U16_TEXT(str) u##str
|
||||
|
||||
#define HGL_OS_NAME OS_TEXT("Android")
|
||||
#define HGL_LIB_OS "Android" //库操作系统前缀
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#define HGL_PLUGIN_FRONTNAME "libCMP." //插件文件名前缀
|
||||
#define HGL_PLUGIN_EXTNAME ".so" //插件文件扩展名
|
||||
#define HGL_PLUGIN_FUNC extern "C" //插件函数定义
|
||||
|
||||
#define HGL_DIRECTORY_SEPARATOR '/' //目录分隔符
|
||||
#define HGL_DIRECTORY_SEPARATOR_STR OS_TEXT("/") //目录分隔符
|
||||
#define HGL_DIRECTORY_SEPARATOR_U8STR U8_TEXT("/") //目录分隔符
|
||||
|
||||
#define HGL_LINE_END "\n" //换行符
|
||||
#define HGL_LINE_END_SIZE 1 //换行符长度
|
||||
|
||||
#define HGL_MEM_ALIGN 16 //内存对齐字节数
|
||||
|
||||
#define HGL_MAX_PATH _POSIX_PATH_MAX
|
||||
|
||||
#define HGL_FMT_I64 "%lld"
|
||||
#define HGL_FMT_U64 "%llu"
|
||||
#define HGL_FMT_DOUBLE "%lf"
|
||||
#define HGL_FMT_LONG_DOUBLE "%le"
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#include<malloc.h>
|
||||
#include<stdlib.h>
|
||||
#include<hgl/platform/os/PosixThread.h>
|
||||
|
||||
#define hgl_malloc(size) memalign(HGL_MEM_ALIGN,size) //这个所有版本linux libc都支持
|
||||
//#define hgl_malloc(size) aligned_alloc(HGL_MEM_ALIGN,size) //这个是C11新增,需要libc 2.16
|
||||
#define hgl_realloc(ptr,size) realloc(ptr,size)
|
||||
#define hgl_free free
|
||||
|
||||
template<typename T>
|
||||
inline T *hgl_aligned_malloc(size_t n)
|
||||
{
|
||||
return (T *)memalign(alignof(T),n*sizeof(T));
|
||||
}
|
||||
|
||||
#define OS_EXTERNAL_H <dlfcn.h>
|
||||
typedef void * ExternalModulePointer;
|
||||
#define pi_get dlsym
|
||||
#define pi_close dlclose
|
||||
|
||||
#define iconv_str char *
|
||||
|
||||
#define hgl_stat64 stat
|
||||
#define hgl_open64 open
|
||||
#define hgl_lseek64 lseek
|
||||
#define hgl_tell64(fp) lseek(fp,0,SEEK_CUR)
|
||||
#define hgl_fstat64 fstat
|
||||
#define hgl_lstat64 lstat
|
||||
#define hgl_read64 read
|
||||
#define hgl_write64 write
|
||||
#define hgl_pread64 pread
|
||||
#define hgl_pwrite64 pwrite
|
||||
|
||||
#define struct_stat64 struct stat
|
||||
#define struct_dirent64 struct dirent
|
||||
#define hgl_dirent64 dirent
|
||||
#define hgl_readdir64 readdir
|
||||
|
||||
#define sprintf_s snprintf
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
//初始化Android支持,以下函数二选一
|
||||
|
||||
#include<jni.h>
|
||||
|
||||
void InitAndroidSupport(JNIEnv *env,jobject obj); //JNI混编模式初始化Android支持
|
||||
|
||||
struct ANativeActivity;
|
||||
void InitAndroidSupport(struct ANativeActivity *app); //NativeActivity模式初始化Android支持
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#endif//HGL_OS_ANDROID_INCLUDE
|
83
inc/hgl/platform/os/BSD.h
Normal file
83
inc/hgl/platform/os/BSD.h
Normal file
@@ -0,0 +1,83 @@
|
||||
#ifndef HGL_OS_BSD_INCLUDE
|
||||
#define HGL_OS_BSD_INCLUDE
|
||||
|
||||
#include<limits.h>
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
using u32char =char32_t;
|
||||
using u16char =char16_t;
|
||||
using os_char =char;
|
||||
#define to_oschar to_u8
|
||||
#define OS_TEXT(str) u8##str
|
||||
#define U8_TEXT(str) u8##str
|
||||
#define U16_TEXT(str) u##str
|
||||
|
||||
#if defined(__FreeBSD__)||defined(__FreeBSD)
|
||||
#define HGL_OS_NAME OS_TEXT("FreeBSD")
|
||||
#define HGL_LIB_OS_NAME "FreeBSD"
|
||||
#elif defined(__NetBSD__)||defined(__NetBSD)
|
||||
#define HGL_OS_NAME OS_TEXT("NetBSD")
|
||||
#define HGL_LIB_OS_NAME "NetBSD"
|
||||
#elif defined(__OpenBSD__)||defined(__OPENBSD)
|
||||
#define HGL_OS_NAME OS_TEXT("OpenBSD")
|
||||
#define HGL_LIB_OS_NAME "OpenBSD"
|
||||
#else
|
||||
#define HGL_OS_NAME OS_TEXT("BSD")
|
||||
#define HGL_LIB_OS_NAME "BSD"
|
||||
#endif//
|
||||
|
||||
#define HGL_LIB_OS "BSD" //库操作系统前缀
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#define HGL_PLUGIN_FRONTNAME "libCMP." //插件文件名前缀
|
||||
#define HGL_PLUGIN_EXTNAME ".so" //插件文件扩展名
|
||||
#define HGL_PLUGIN_FUNC extern "C" //插件函数定义
|
||||
|
||||
#define HGL_DIRECTORY_SEPARATOR '/' //目录分隔符
|
||||
#define HGL_DIRECTORY_SEPARATOR_STR OS_TEXT("/") //目录分隔符
|
||||
#define HGL_DIRECTORY_SEPARATOR_U8STR U8_TEXT("/") //目录分隔符
|
||||
|
||||
#define HGL_LINE_END "\n" //换行符
|
||||
#define HGL_LINE_END_SIZE 1 //换行符长度
|
||||
|
||||
#define HGL_MEM_ALIGN 16 //内存对齐字节数
|
||||
|
||||
#define HGL_MAX_PATH _POSIX_PATH_MAX
|
||||
|
||||
#define HGL_FMT_I64 "%lld"
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#include<stdlib.h>
|
||||
#include<hgl/platform/os/PosixThread.h>
|
||||
|
||||
#define hgl_malloc(size) aligned_alloc(HGL_MEM_ALIGN,size) //这个是C11新增,需要libc 2.16
|
||||
#define hgl_realloc realloc
|
||||
#define hgl_free free
|
||||
|
||||
template<typename T>
|
||||
inline T *hgl_aligned_malloc(size_t n)
|
||||
{
|
||||
return (T *)aligned_alloc(alignof(T),n*sizeof(T));
|
||||
}
|
||||
|
||||
#define OS_EXTERNAL_H <dlfcn.h>
|
||||
typedef void * ExternalModulePointer;
|
||||
#define pi_get dlsym
|
||||
#define pi_close dlclose
|
||||
|
||||
typedef pthread_mutex_t hgl_thread_mutex;
|
||||
|
||||
#define hgl_stat64 stat
|
||||
#define hgl_open64 open
|
||||
#define hgl_lseek64 lseek
|
||||
#define hgl_tell64(fp) lseek(fp,0,SEEK_CUR)
|
||||
#define hgl_fstat64 fstat
|
||||
#define hgl_lstat64 lstat
|
||||
#define hgl_read64 read
|
||||
#define hgl_write64 write
|
||||
#define hgl_pread64 pread
|
||||
#define hgl_pwrite64 pwrite
|
||||
|
||||
#define struct_stat64 struct stat
|
||||
#define struct_dirent64 struct dirent
|
||||
#define hgl_dirent64 dirent
|
||||
#define hgl_readdir64 readdir
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#endif//HGL_OS_BSD_INCLUDE
|
75
inc/hgl/platform/os/Linux.h
Normal file
75
inc/hgl/platform/os/Linux.h
Normal file
@@ -0,0 +1,75 @@
|
||||
#ifndef HGL_OS_LINUX_INCLUDE
|
||||
#define HGL_OS_LINUX_INCLUDE
|
||||
|
||||
#include<limits.h>
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
using u32char =char32_t;
|
||||
using u16char =char16_t;
|
||||
using os_char =char;
|
||||
#define to_oschar to_u8
|
||||
#define OS_TEXT(str) u8##str
|
||||
#define U8_TEXT(str) u8##str
|
||||
#define U16_TEXT(str) u##str
|
||||
|
||||
#define HGL_OS_NAME OS_TEXT("Linux")
|
||||
#define HGL_LIB_OS "Linux" //库操作系统前缀
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#define HGL_PLUGIN_FRONTNAME "libCMP." //插件文件名前缀
|
||||
#define HGL_PLUGIN_EXTNAME ".so" //插件文件扩展名
|
||||
#define HGL_PLUGIN_FUNC extern "C" //插件函数定义
|
||||
|
||||
#define HGL_DIRECTORY_SEPARATOR '/' //目录分隔符
|
||||
#define HGL_DIRECTORY_SEPARATOR_STR OS_TEXT("/") //目录分隔符
|
||||
#define HGL_DIRECTORY_SEPARATOR_U8STR U8_TEXT("/") //目录分隔符
|
||||
|
||||
#define HGL_LINE_END "\n" //换行符
|
||||
#define HGL_LINE_END_SIZE 1 //换行符长度
|
||||
|
||||
#define HGL_MEM_ALIGN 16 //内存对齐字节数
|
||||
|
||||
#define HGL_MAX_PATH _POSIX_PATH_MAX
|
||||
|
||||
#define HGL_FMT_I64 "%lld"
|
||||
#define HGL_FMT_U64 "%llu"
|
||||
#define HGL_FMT_DOUBLE "%lf"
|
||||
#define HGL_FMT_LONG_DOUBLE "%le"
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#include<malloc.h>
|
||||
#include<stdlib.h>
|
||||
#include<hgl/platform/os/PosixThread.h>
|
||||
|
||||
//#define hgl_malloc(size) memalign(HGL_MEM_ALIGN,size) //这个所有版本linux libc都支持
|
||||
#define hgl_malloc(size) aligned_alloc(HGL_MEM_ALIGN,size) //这个是C11新增,需要libc 2.16
|
||||
#define hgl_realloc(ptr,size) realloc(ptr,size)
|
||||
#define hgl_free free
|
||||
|
||||
template<typename T>
|
||||
inline T *hgl_aligned_malloc(size_t n)
|
||||
{
|
||||
return (T *)aligned_alloc(alignof(T),n*sizeof(T));
|
||||
}
|
||||
|
||||
#define OS_EXTERNAL_H <dlfcn.h>
|
||||
typedef void * ExternalModulePointer;
|
||||
#define pi_get dlsym
|
||||
#define pi_close dlclose
|
||||
|
||||
#define hgl_stat64 stat64
|
||||
#define hgl_open64 open64
|
||||
#define hgl_lseek64 lseek64
|
||||
#define hgl_tell64(fp) lseek64(fp,0,SEEK_CUR)
|
||||
#define hgl_fstat64 fstat64
|
||||
#define hgl_lstat64 lstat64
|
||||
#define hgl_read64 read
|
||||
#define hgl_write64 write
|
||||
#define hgl_pread64 pread64
|
||||
#define hgl_pwrite64 pwrite64
|
||||
|
||||
#define struct_stat64 struct stat64
|
||||
#define struct_dirent64 struct dirent64
|
||||
#define hgl_dirent64 dirent64
|
||||
#define hgl_readdir64 readdir64
|
||||
|
||||
#define sprintf_s snprintf
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#endif//HGL_OS_LINUX_INCLUDE
|
80
inc/hgl/platform/os/MSWindows.h
Normal file
80
inc/hgl/platform/os/MSWindows.h
Normal file
@@ -0,0 +1,80 @@
|
||||
#ifndef HGL_OS_WIN_INCLUDE
|
||||
#define HGL_OS_WIN_INCLUDE
|
||||
|
||||
#include<malloc.h>
|
||||
#include<winsock2.h> //winsock2必须在Windows.h前面,不然会报错
|
||||
#include<windows.h>
|
||||
|
||||
#undef min
|
||||
#undef max
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
using u32char =char32_t;
|
||||
using u16char =wchar_t;
|
||||
using os_char =wchar_t;
|
||||
#define to_oschar to_u16
|
||||
#define OS_TEXT(str) L##str
|
||||
#define U8_TEXT(str) u8##str
|
||||
#define U16_TEXT(str) L##str
|
||||
|
||||
#define HGL_OS_NAME OS_TEXT("Windows")
|
||||
|
||||
#if HGL_CPU == HGL_CPU_X86_32
|
||||
#define HGL_LIB_OS "Win32" //库操作系统前缀
|
||||
#elif HGL_CPU == HGL_CPU_X86_64
|
||||
#define HGL_LIB_OS "Win64" //库操作系统前缀
|
||||
#endif//HGL_CPU
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#define HGL_PLUGIN_FRONTNAME OS_TEXT("CMP.") //插件文件名前缀
|
||||
#define HGL_PLUGIN_EXTNAME OS_TEXT(".DLL") //插件文件扩展名
|
||||
#define HGL_PLUGIN_FUNC extern "C" __declspec(dllexport) //插件函数定义
|
||||
|
||||
#define HGL_DIRECTORY_SEPARATOR OS_TEXT('\\') //目录分隔符
|
||||
#define HGL_DIRECTORY_SEPARATOR_STR OS_TEXT("\\") //目录分隔符
|
||||
#define HGL_DIRECTORY_SEPARATOR_U8STR U8_TEXT("\\")
|
||||
|
||||
#define HGL_LINE_END OS_TEXT("\r\n") //换行符
|
||||
#define HGL_LINE_END_SIZE 2 //换行符长度
|
||||
|
||||
#define HGL_MAX_PATH MAX_PATH
|
||||
|
||||
#define HGL_MEM_ALIGN 16 //内存对齐字节数
|
||||
|
||||
#define HGL_GL_WINDOW_INCLUDE_FILE <hgl/platform/WinOpenGL.h> //指定OpenGL窗口引用头文件
|
||||
#define HGL_GL_WINDOW_CLASS WinGLWindow //指定OpenGL窗口类名称
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#if HGL_COMPILER == HGL_COMPILER_Microsoft
|
||||
#define hgl_malloc(size) _aligned_malloc(size,HGL_MEM_ALIGN)
|
||||
#define hgl_realloc(ptr,size) _aligned_realloc(ptr,size,HGL_MEM_ALIGN)
|
||||
#define hgl_free _aligned_free
|
||||
|
||||
template<typename T>
|
||||
inline T *hgl_aligned_malloc(size_t n)
|
||||
{
|
||||
return (T *)_aligned_malloc(n*sizeof(T),alignof(T));
|
||||
}
|
||||
#else
|
||||
#define hgl_malloc(size) memalign(HGL_MEM_ALIGN,size)
|
||||
#define hgl_realloc(ptr,size) realloc(ptr,size)
|
||||
#define hgl_free free
|
||||
#endif//
|
||||
|
||||
#define OS_EXTERNAL_H <winbase.h>
|
||||
typedef HMODULE ExternalModulePointer;
|
||||
#define pi_get GetProcAddress
|
||||
#define pi_close FreeLibrary
|
||||
|
||||
#define struct_stat64 struct _stat64
|
||||
//#define hgl_stat64 _stat64
|
||||
#define hgl_lseek64 _lseeki64
|
||||
#define hgl_tell64(fp) _telli64(fp)
|
||||
#define hgl_fstat64 _fstati64
|
||||
#define hgl_lstat64 _wstat64
|
||||
#define hgl_read64 _read
|
||||
#define hgl_write64 _write
|
||||
|
||||
using hgl_thread_mutex =CRITICAL_SECTION;
|
||||
using thread_ptr =HANDLE;
|
||||
#define THREAD_FUNC DWORD WINAPI
|
||||
#define HGL_THREAD_DETACH_SELF
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#endif//HGL_OS_WIN_INCLUDE
|
78
inc/hgl/platform/os/MacOS.h
Normal file
78
inc/hgl/platform/os/MacOS.h
Normal file
@@ -0,0 +1,78 @@
|
||||
#ifndef HGL_OS_MACOS_INCLUDE
|
||||
#define HGL_OS_MACOS_INCLUDE
|
||||
|
||||
#include<dirent.h>
|
||||
//------------------------------------------------------------------
|
||||
using u32char =char32_t;
|
||||
using u16char =char16_t;
|
||||
using os_char =char;
|
||||
#define to_oschar to_u8
|
||||
#define OS_TEXT(str) u8##str
|
||||
#define U8_TEXT(str) u8##str
|
||||
#define U16_TEXT(str) u##str
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#if HGL_OS == HGL_OS_iOS
|
||||
#define HGL_OS_NAME OS_TEXT("iOS")
|
||||
#define HGL_LIB_OS "iOS" //库操作系统前缀
|
||||
#else
|
||||
#define HGL_OS_NAME OS_TEXT("macOS")
|
||||
#define HGL_LIB_OS "mac" //库操作系统前缀
|
||||
#endif//HGL_OS == HGL_OS_iOS
|
||||
|
||||
#define HGL_PLUGIN_FRONTNAME "libCMP." //插件文件名前缀
|
||||
#define HGL_PLUGIN_EXTNAME OS_TEXT(".dylib") //插件文件扩展名
|
||||
#define HGL_PLUGIN_FUNC extern "C" //插件函数定义
|
||||
|
||||
#define HGL_DIRECTORY_SEPARATOR '/' //目录分隔符
|
||||
#define HGL_DIRECTORY_SEPARATOR_STR OS_TEXT("/") //目录分隔符
|
||||
#define HGL_DIRECTORY_SEPARATOR_U8STR U8_TEXT("/") //目录分隔符
|
||||
|
||||
#define HGL_LINE_END "\n" //换行符
|
||||
#define HGL_LINE_END_SIZE 1 //换行符长度
|
||||
|
||||
#define HGL_MEM_ALIGN 16 //内存对齐字节数
|
||||
|
||||
#define HGL_MAX_PATH __DARWIN_MAXPATHLEN
|
||||
|
||||
#define HGL_FMT_I64 "%lld"
|
||||
#define HGL_FMT_U64 "%llu"
|
||||
#define HGL_FMT_DOUBLE "%lf"
|
||||
#define HGL_FMT_LONG_DOUBLE "%le"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#include<hgl/platform/os/PosixThread.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
#define hgl_malloc(size) malloc(size)
|
||||
#define hgl_realloc(ptr,size) realloc(ptr,size)
|
||||
#define hgl_free free
|
||||
|
||||
template<typename T>
|
||||
inline T *hgl_aligned_malloc(size_t n)
|
||||
{
|
||||
return (T *)hgl_malloc(n*sizeof(T));
|
||||
}
|
||||
|
||||
#define OS_EXTERNAL_H <dlfcn.h>
|
||||
using ExternalModulePointer=void *;
|
||||
#define pi_get dlsym
|
||||
#define pi_close dlclose
|
||||
|
||||
#define hgl_stat64 stat
|
||||
#define hgl_open64 open
|
||||
#define hgl_lseek64 lseek
|
||||
#define hgl_tell64(fp) lseek(fp,0,SEEK_CUR)
|
||||
#define hgl_fstat64 fstat
|
||||
#define hgl_lstat64 lstat
|
||||
#define hgl_read64 read
|
||||
#define hgl_write64 write
|
||||
#define hgl_pread64 pread
|
||||
#define hgl_pwrite64 pwrite
|
||||
|
||||
#define struct_stat64 struct stat
|
||||
#define struct_dirent64 struct dirent
|
||||
#define hgl_dirent64 dirent
|
||||
#define hgl_readdir64 readdir
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#endif//HGL_OS_MACOS_INCLUDE
|
15
inc/hgl/platform/os/PosixThread.h
Normal file
15
inc/hgl/platform/os/PosixThread.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef HGL_POSIX_THREAD_INCLUDE
|
||||
#define HGL_POSIX_THREAD_INCLUDE
|
||||
|
||||
#include<pthread.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
using hgl_thread_mutex =pthread_mutex_t;
|
||||
|
||||
using thread_ptr =pthread_t;
|
||||
using THREAD_FUNC =void *;
|
||||
|
||||
#define HGL_THREAD_DETACH_SELF pthread_detach(pthread_self());
|
||||
}//namespace hgl
|
||||
#endif//HGL_POSIX_THREAD_INCLUDE
|
Reference in New Issue
Block a user