#ifndef SSG #define SSG #define SSG_Api #ifdef SSG_Api #define SSGC_API __declspec(dllexport) #define ssgcDecl _cdecl #else #define SSGC_API __declspec(dllimport) #endif #include "framework.h" #include "GLAD/gl.h" #include "glad/wgl.h" #include "glfw/glfw3.h" #include #pragma comment(lib, "glfw3.lib") #pragma region debug SSGC_API void printShaderCode(char* const* code); #pragma endregion #pragma region Internal extern __m128* defaultVecPtr; #define ALIGN(simdVec) _mm_loadu_ps(&simdVec) extern GladGLContext* currentContext; typedef struct glfwContext { int(ssgcDecl* Init)(void); void(ssgcDecl* Terminate)(void); void(ssgcDecl* InitHint)(int hint, int value); void(ssgcDecl* GetVersion)(int* major, int* minor, int* rev); char* (ssgcDecl* GetVersionString)(void); int(ssgcDecl* GetError)(char** description); GLFWerrorfun(ssgcDecl* SetErrorCallback)(GLFWerrorfun callback); GLFWmonitor** (ssgcDecl* GetMonitors)(int* count); GLFWmonitor* (ssgcDecl* GetPrimaryMonitor)(void); void(ssgcDecl* GetMonitorPos)(GLFWmonitor* monitor, int* xpos, int* ypos); void(ssgcDecl* GetMonitorWorkarea)(GLFWmonitor* monitor, int* xpos, int* ypos, int* width, int* height); void(ssgcDecl* GetMonitorPhysicalSize)(GLFWmonitor* monitor, int* widthMM, int* heightMM); void(ssgcDecl* GetMonitorContentScale)(GLFWmonitor* monitor, float* xscale, float* yscale); char* (ssgcDecl* GetMonitorName)(GLFWmonitor* monitor); void(ssgcDecl* SetMonitorUserPointer)(GLFWmonitor* monitor, void* pointer); void* (ssgcDecl* GetMonitorUserPointer)(GLFWmonitor* monitor); GLFWmonitorfun(ssgcDecl* SetMonitorCallback)(GLFWmonitorfun callback); GLFWvidmode* (ssgcDecl* GetVideoModes)(GLFWmonitor* monitor, int* count); GLFWvidmode* (ssgcDecl* GetVideoMode)(GLFWmonitor* monitor); void(ssgcDecl* SetGamma)(GLFWmonitor* monitor, float gamma); GLFWgammaramp* (ssgcDecl* GetGammaRamp)(GLFWmonitor* monitor); void(ssgcDecl* SetGammaRamp)(GLFWmonitor* monitor, GLFWgammaramp* ramp); void(ssgcDecl* DefaultWindowHints)(void); void(ssgcDecl* WindowHint)(int hint, int value); void(ssgcDecl* WindowHintString)(int hint, char* value); GLFWwindow* (ssgcDecl* CreateWindowProc)(int width, int height, char* title, GLFWmonitor* monitor, GLFWwindow* share); void(ssgcDecl* DestroyWindow)(GLFWwindow* window); int(ssgcDecl* WindowShouldClose)(GLFWwindow* window); void(ssgcDecl* SetWindowShouldClose)(GLFWwindow* window, int value); void(ssgcDecl* SetWindowTitle)(GLFWwindow* window, char* title); void(ssgcDecl* SetWindowIcon)(GLFWwindow* window, int count, GLFWimage* images); void(ssgcDecl* GetWindowPos)(GLFWwindow* window, int* xpos, int* ypos); void(ssgcDecl* SetWindowPos)(GLFWwindow* window, int xpos, int ypos); void(ssgcDecl* GetWindowSize)(GLFWwindow* window, int* width, int* height); void(ssgcDecl* SetWindowSizeLimits)(GLFWwindow* window, int minwidth, int minheight, int maxwidth, int maxheight); void(ssgcDecl* SetWindowAspectRatio)(GLFWwindow* window, int numer, int denom); void(ssgcDecl* SetWindowSize)(GLFWwindow* window, int width, int height); void(ssgcDecl* GetFramebufferSize)(GLFWwindow* window, int* width, int* height); void(ssgcDecl* GetWindowFrameSize)(GLFWwindow* window, int* left, int* top, int* right, int* bottom); void(ssgcDecl* GetWindowContentScale)(GLFWwindow* window, float* xscale, float* yscale); float(ssgcDecl* GetWindowOpacity)(GLFWwindow* window); void(ssgcDecl* SetWindowOpacity)(GLFWwindow* window, float opacity); void(ssgcDecl* IconifyWindow)(GLFWwindow* window); void(ssgcDecl* RestoreWindow)(GLFWwindow* window); void(ssgcDecl* MaximizeWindow)(GLFWwindow* window); void(ssgcDecl* ShowWindow)(GLFWwindow* window); void(ssgcDecl* HideWindow)(GLFWwindow* window); void(ssgcDecl* FocusWindow)(GLFWwindow* window); void(ssgcDecl* RequestWindowAttention)(GLFWwindow* window); GLFWmonitor* (ssgcDecl* GetWindowMonitor)(GLFWwindow* window); void(ssgcDecl* SetWindowMonitor)(GLFWwindow* window, GLFWmonitor* monitor, int xpos, int ypos, int width, int height, int refreshRate); int(ssgcDecl* GetWindowAttrib)(GLFWwindow* window, int attrib); void(ssgcDecl* SetWindowAttrib)(GLFWwindow* window, int attrib, int value); void(ssgcDecl* SetWindowUserPointer)(GLFWwindow* window, void* pointer); void* (ssgcDecl* GetWindowUserPointer)(GLFWwindow* window); GLFWwindowposfun(ssgcDecl* SetWindowPosCallback)(GLFWwindow* window, GLFWwindowposfun callback); GLFWwindowsizefun(ssgcDecl* SetWindowSizeCallback)(GLFWwindow* window, GLFWwindowsizefun callback); GLFWwindowclosefun(ssgcDecl* SetWindowCloseCallback)(GLFWwindow* window, GLFWwindowclosefun callback); GLFWwindowrefreshfun(ssgcDecl* SetWindowRefreshCallback)(GLFWwindow* window, GLFWwindowrefreshfun callback); GLFWwindowfocusfun(ssgcDecl* SetWindowFocusCallback)(GLFWwindow* window, GLFWwindowfocusfun callback); GLFWwindowiconifyfun(ssgcDecl* SetWindowIconifyCallback)(GLFWwindow* window, GLFWwindowiconifyfun callback); GLFWwindowmaximizefun(ssgcDecl* SetWindowMaximizeCallback)(GLFWwindow* window, GLFWwindowmaximizefun callback); GLFWframebuffersizefun(ssgcDecl* SetFramebufferSizeCallback)(GLFWwindow* window, GLFWframebuffersizefun callback); GLFWwindowcontentscalefun(ssgcDecl* SetWindowContentScaleCallback)(GLFWwindow* window, GLFWwindowcontentscalefun callback); void(ssgcDecl* PollEvents)(void); void(ssgcDecl* WaitEvents)(void); void(ssgcDecl* WaitEventsTimeout)(double timeout); void(ssgcDecl* PostEmptyEvent)(void); int(ssgcDecl* GetInputMode)(GLFWwindow* window, int mode); void(ssgcDecl* SetInputMode)(GLFWwindow* window, int mode, int value); int(ssgcDecl* RawMouseMotionSupported)(void); char* (ssgcDecl* GetKeyName)(int key, int scancode); int(ssgcDecl* GetKeyScancode)(int key); int(ssgcDecl* GetKey)(GLFWwindow* window, int key); int(ssgcDecl* GetMouseButton)(GLFWwindow* window, int button); void(ssgcDecl* GetCursorPos)(GLFWwindow* window, double* xpos, double* ypos); void(ssgcDecl* SetCursorPos)(GLFWwindow* window, double xpos, double ypos); GLFWcursor* (ssgcDecl* CreateCursor)(GLFWimage* image, int xhot, int yhot); GLFWcursor* (ssgcDecl* CreateStandardCursor)(int shape); void(ssgcDecl* DestroyCursor)(GLFWcursor* cursor); void(ssgcDecl* SetCursor)(GLFWwindow* window, GLFWcursor* cursor); GLFWkeyfun(ssgcDecl* SetKeyCallback)(GLFWwindow* window, GLFWkeyfun callback); GLFWcharfun(ssgcDecl* SetCharCallback)(GLFWwindow* window, GLFWcharfun callback); GLFWcharmodsfun(ssgcDecl* SetCharModsCallback)(GLFWwindow* window, GLFWcharmodsfun callback); GLFWmousebuttonfun(ssgcDecl* SetMouseButtonCallback)(GLFWwindow* window, GLFWmousebuttonfun callback); GLFWcursorposfun(ssgcDecl* SetCursorPosCallback)(GLFWwindow* window, GLFWcursorposfun callback); GLFWcursorenterfun(ssgcDecl* SetCursorEnterCallback)(GLFWwindow* window, GLFWcursorenterfun callback); GLFWscrollfun(ssgcDecl* SetScrollCallback)(GLFWwindow* window, GLFWscrollfun callback); GLFWdropfun(ssgcDecl* SetDropCallback)(GLFWwindow* window, GLFWdropfun callback); int(ssgcDecl* JoystickPresent)(int jid); float* (ssgcDecl* GetJoystickAxes)(int jid, int* count); unsigned char* (ssgcDecl* GetJoystickButtons)(int jid, int* count); unsigned char* (ssgcDecl* GetJoystickHats)(int jid, int* count); char* (ssgcDecl* GetJoystickName)(int jid); char* (ssgcDecl* GetJoystickGUID)(int jid); void(ssgcDecl* SetJoystickUserPointer)(int jid, void* pointer); void* (ssgcDecl* GetJoystickUserPointer)(int jid); int(ssgcDecl* JoystickIsGamepad)(int jid); GLFWjoystickfun(ssgcDecl* SetJoystickCallback)(GLFWjoystickfun callback); int(ssgcDecl* UpdateGamepadMappings)(char* string); char* (ssgcDecl* GetGamepadName)(int jid); int(ssgcDecl* GetGamepadState)(int jid, GLFWgamepadstate* state); void(ssgcDecl* SetClipboardString)(GLFWwindow* window, char* string); char* (ssgcDecl* GetClipboardString)(GLFWwindow* window); double(ssgcDecl* GetTime)(void); void(ssgcDecl* SetTime)(double time); uint64_t* (ssgcDecl* GetTimerValue)(void); uint64_t* (ssgcDecl* GetTimerFrequency)(void); void(ssgcDecl* MakeContextCurrent)(GLFWwindow* window); GLFWwindow* (ssgcDecl* GetCurrentContext)(void); void(ssgcDecl* SwapBuffers)(GLFWwindow* window); void(ssgcDecl* SwapInterval)(int interval); int(ssgcDecl* ExtensionSupported)(char* extension); GLFWglproc(ssgcDecl* GetProcAddress)(char* procname); int(ssgcDecl* VulkanSupported)(void); char** (ssgcDecl* GetRequiredInstanceExtensions)(uint32_t* count); #if defined(VK_VERSION_1_0) GLFWvkproc(ssgcDecl* GetInstanceProcAddress)(VkInstance instance, char* procname); int(ssgcDecl* GetPhysicalDevicePresentationSupport)(VkInstance instance, VkPhysicalDevice device, uint32_t* queuefamily); VkResult(ssgcDecl* CreateWindowSurface)(VkInstance instance, GLFWwindow* window, VkAllocationCallbacks* allocator, VkSurfaceKHR* surface); #endif }glfwContext; extern glfwContext* glfw; #pragma endregion SSGC_API char* infolog[512]; SSGC_API glfwContext* _cdecl initGL(int majorVersion, int minorVersion, glfwContext* ptr); SSGC_API int _cdecl initGLAD(void); SSGC_API unsigned int _cdecl loadShaderCode(char* const shaderCode, GLint shadertype); SSGC_API unsigned int _cdecl linkShaderProgram(GLuint shadertype); SSGC_API void _cdecl setCurrentGLcontext(GladGLContext* contextPtr); SSGC_API char* _cdecl readLog(void); //linear related function SSGC_API __m128* __cdecl set_m128ptr_default(); #pragma region mat define typedef union matrix2map { __m128 colum[2]; float m[4][2]; }matrix2map; typedef struct matrix3map { __m128 colum[3]; float m[4][3]; }matrix3map; typedef union matrix4map { __m128 colum[4]; float m[4][4]; }matrix4map; #pragma endregion #pragma region mat2 SSGC_API _inline void __cdecl transpose2to3(matrix2map* source, matrix3map* target); SSGC_API _inline void __cdecl transpose2to4(matrix2map* source, matrix4map* target); SSGC_API _inline void __cdecl deinit_mat2(matrix2map* mat); #pragma endregion #pragma region mat3 SSGC_API __inline void _cdecl transpose3to2(matrix3map* source, matrix2map* target); SSGC_API __inline void _cdecl transpose3to3(matrix3map* source, matrix3map* target); SSGC_API __inline void _cdecl transpose3to4(matrix3map* source, matrix4map* target); SSGC_API _inline float _cdecl det_mat3(matrix3map* mat); SSGC_API __inline float det_mat3_internal(__m128 const c1, __m128 const c2, __m128 const c3); #pragma endregion #pragma region mat4 //type and function for 4 colum matrix SSGC_API __inline void __cdecl transpose4to2(matrix4map* source, matrix4map* target); SSGC_API __inline void __cdecl transpose4to4(matrix4map* matrix, matrix4map* target); SSGC_API __inline float __cdecl det_mat4(matrix4map* matPtr, matrix4map* transpose); SSGC_API __inline void __cdecl deinit_mat4(matrix4map* matPtr); #pragma endregion #endif // !SSG