initial commit
This commit is contained in:
474
libs/glfw/lib/win32/platform.h
Normal file
474
libs/glfw/lib/win32/platform.h
Normal file
@ -0,0 +1,474 @@
|
||||
//========================================================================
|
||||
// GLFW - An OpenGL framework
|
||||
// File: platform.h
|
||||
// Platform: Windows
|
||||
// API version: 2.6
|
||||
// WWW: http://glfw.sourceforge.net
|
||||
//------------------------------------------------------------------------
|
||||
// Copyright (c) 2002-2006 Camilla Berglund
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would
|
||||
// be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not
|
||||
// be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#ifndef _platform_h_
|
||||
#define _platform_h_
|
||||
|
||||
|
||||
// This is the Windows version of GLFW
|
||||
#define _GLFW_WIN32
|
||||
|
||||
|
||||
// Include files
|
||||
#include <windows.h>
|
||||
#include <mmsystem.h>
|
||||
#include "../../include/GL/glfw.h"
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Hack: Define things that some <windows.h>'s do not define
|
||||
//========================================================================
|
||||
|
||||
// Some old versions of w32api (used by MinGW and Cygwin) define
|
||||
// WH_KEYBOARD_LL without typedef:ing KBDLLHOOKSTRUCT (!)
|
||||
#if defined(__MINGW32__) || defined(__CYGWIN__)
|
||||
#include <w32api.h>
|
||||
#if defined(WH_KEYBOARD_LL) && (__W32API_MAJOR_VERSION == 1) && (__W32API_MINOR_VERSION <= 2)
|
||||
#undef WH_KEYBOARD_LL
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// ** NOTE ** If this gives you compiler errors and you are using MinGW
|
||||
// (or Dev-C++), update to w32api version 1.3 or later:
|
||||
// http://sourceforge.net/project/showfiles.php?group_id=2435
|
||||
//------------------------------------------------------------------------
|
||||
#ifndef WH_KEYBOARD_LL
|
||||
#define WH_KEYBOARD_LL 13
|
||||
typedef struct tagKBDLLHOOKSTRUCT {
|
||||
DWORD vkCode;
|
||||
DWORD scanCode;
|
||||
DWORD flags;
|
||||
DWORD time;
|
||||
DWORD dwExtraInfo;
|
||||
} KBDLLHOOKSTRUCT, FAR *LPKBDLLHOOKSTRUCT, *PKBDLLHOOKSTRUCT;
|
||||
#endif // WH_KEYBOARD_LL
|
||||
|
||||
#ifndef LLKHF_ALTDOWN
|
||||
#define LLKHF_ALTDOWN 0x00000020
|
||||
#endif
|
||||
|
||||
#ifndef SPI_SETSCREENSAVERRUNNING
|
||||
#define SPI_SETSCREENSAVERRUNNING 97
|
||||
#endif
|
||||
#ifndef SPI_GETANIMATION
|
||||
#define SPI_GETANIMATION 72
|
||||
#endif
|
||||
#ifndef SPI_SETANIMATION
|
||||
#define SPI_SETANIMATION 73
|
||||
#endif
|
||||
#ifndef SPI_GETFOREGROUNDLOCKTIMEOUT
|
||||
#define SPI_GETFOREGROUNDLOCKTIMEOUT 0x2000
|
||||
#endif
|
||||
#ifndef SPI_SETFOREGROUNDLOCKTIMEOUT
|
||||
#define SPI_SETFOREGROUNDLOCKTIMEOUT 0x2001
|
||||
#endif
|
||||
|
||||
#ifndef CDS_FULLSCREEN
|
||||
#define CDS_FULLSCREEN 4
|
||||
#endif
|
||||
|
||||
#ifndef PFD_GENERIC_ACCELERATED
|
||||
#define PFD_GENERIC_ACCELERATED 0x00001000
|
||||
#endif
|
||||
#ifndef PFD_DEPTH_DONTCARE
|
||||
#define PFD_DEPTH_DONTCARE 0x20000000
|
||||
#endif
|
||||
|
||||
#ifndef ENUM_CURRENT_SETTINGS
|
||||
#define ENUM_CURRENT_SETTINGS -1
|
||||
#endif
|
||||
#ifndef ENUM_REGISTRY_SETTINGS
|
||||
#define ENUM_REGISTRY_SETTINGS -2
|
||||
#endif
|
||||
|
||||
#ifndef WM_MOUSEWHEEL
|
||||
#define WM_MOUSEWHEEL 0x020A
|
||||
#endif
|
||||
#ifndef WHEEL_DELTA
|
||||
#define WHEEL_DELTA 120
|
||||
#endif
|
||||
|
||||
#ifndef WM_XBUTTONDOWN
|
||||
#define WM_XBUTTONDOWN 0x020B
|
||||
#endif
|
||||
#ifndef WM_XBUTTONUP
|
||||
#define WM_XBUTTONUP 0x020C
|
||||
#endif
|
||||
#ifndef XBUTTON1
|
||||
#define XBUTTON1 1
|
||||
#endif
|
||||
#ifndef XBUTTON2
|
||||
#define XBUTTON2 2
|
||||
#endif
|
||||
|
||||
// wglSwapIntervalEXT typedef (Win32 buffer-swap interval control)
|
||||
typedef int (APIENTRY * WGLSWAPINTERVALEXT_T) (int);
|
||||
// wglChoosePixelFormatARB typedef
|
||||
typedef BOOL (WINAPI * WGLCHOOSEPIXELFORMATARB_T) (HDC, const int *, const FLOAT *, UINT, int *, UINT *);
|
||||
// wglGetPixelFormatAttribivARB typedef
|
||||
typedef BOOL (WINAPI * WGLGETPIXELFORMATATTRIBIVARB_T) (HDC, int, int, UINT, const int *, int *);
|
||||
// wglGetExtensionStringEXT typedef
|
||||
typedef const char *(APIENTRY * WGLGETEXTENSIONSSTRINGEXT_T)( void );
|
||||
// wglGetExtensionStringARB typedef
|
||||
typedef const char *(APIENTRY * WGLGETEXTENSIONSSTRINGARB_T)( HDC );
|
||||
|
||||
#define WGL_DRAW_TO_WINDOW_ARB 0x2001
|
||||
#define WGL_SUPPORT_OPENGL_ARB 0x2010
|
||||
#define WGL_ACCELERATION_ARB 0x2003
|
||||
#define WGL_FULL_ACCELERATION_ARB 0x2027
|
||||
#define WGL_DOUBLE_BUFFER_ARB 0x2011
|
||||
#define WGL_STEREO_ARB 0x2012
|
||||
#define WGL_COLOR_BITS_ARB 0x2014
|
||||
#define WGL_RED_BITS_ARB 0x2015
|
||||
#define WGL_GREEN_BITS_ARB 0x2017
|
||||
#define WGL_BLUE_BITS_ARB 0x2019
|
||||
#define WGL_ALPHA_BITS_ARB 0x201B
|
||||
#define WGL_ACCUM_BITS_ARB 0x201D
|
||||
#define WGL_ACCUM_RED_BITS_ARB 0x201E
|
||||
#define WGL_ACCUM_GREEN_BITS_ARB 0x201F
|
||||
#define WGL_ACCUM_BLUE_BITS_ARB 0x2020
|
||||
#define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
|
||||
#define WGL_DEPTH_BITS_ARB 0x2022
|
||||
#define WGL_STENCIL_BITS_ARB 0x2023
|
||||
#define WGL_AUX_BUFFERS_ARB 0x2024
|
||||
#define WGL_SAMPLE_BUFFERS_ARB 0x2041
|
||||
#define WGL_SAMPLES_ARB 0x2042
|
||||
|
||||
|
||||
//========================================================================
|
||||
// DLLs that are loaded at glfwInit()
|
||||
//========================================================================
|
||||
|
||||
// gdi32.dll function pointer typedefs
|
||||
#ifndef _GLFW_NO_DLOAD_GDI32
|
||||
typedef int (WINAPI * CHOOSEPIXELFORMAT_T) (HDC,CONST PIXELFORMATDESCRIPTOR*);
|
||||
typedef int (WINAPI * DESCRIBEPIXELFORMAT_T) (HDC,int,UINT,LPPIXELFORMATDESCRIPTOR);
|
||||
typedef int (WINAPI * GETPIXELFORMAT_T) (HDC);
|
||||
typedef BOOL (WINAPI * SETPIXELFORMAT_T) (HDC,int,const PIXELFORMATDESCRIPTOR*);
|
||||
typedef BOOL (WINAPI * SWAPBUFFERS_T) (HDC);
|
||||
#endif // _GLFW_NO_DLOAD_GDI32
|
||||
|
||||
// winmm.dll function pointer typedefs
|
||||
#ifndef _GLFW_NO_DLOAD_WINMM
|
||||
typedef MMRESULT (WINAPI * JOYGETDEVCAPSA_T) (UINT,LPJOYCAPSA,UINT);
|
||||
typedef MMRESULT (WINAPI * JOYGETPOS_T) (UINT,LPJOYINFO);
|
||||
typedef MMRESULT (WINAPI * JOYGETPOSEX_T) (UINT,LPJOYINFOEX);
|
||||
typedef DWORD (WINAPI * TIMEGETTIME_T) (void);
|
||||
#endif // _GLFW_NO_DLOAD_WINMM
|
||||
|
||||
|
||||
// gdi32.dll shortcuts
|
||||
#ifndef _GLFW_NO_DLOAD_GDI32
|
||||
#define _glfw_ChoosePixelFormat _glfwLibrary.Libs.ChoosePixelFormat
|
||||
#define _glfw_DescribePixelFormat _glfwLibrary.Libs.DescribePixelFormat
|
||||
#define _glfw_GetPixelFormat _glfwLibrary.Libs.GetPixelFormat
|
||||
#define _glfw_SetPixelFormat _glfwLibrary.Libs.SetPixelFormat
|
||||
#define _glfw_SwapBuffers _glfwLibrary.Libs.SwapBuffers
|
||||
#else
|
||||
#define _glfw_ChoosePixelFormat ChoosePixelFormat
|
||||
#define _glfw_DescribePixelFormat DescribePixelFormat
|
||||
#define _glfw_GetPixelFormat GetPixelFormat
|
||||
#define _glfw_SetPixelFormat SetPixelFormat
|
||||
#define _glfw_SwapBuffers SwapBuffers
|
||||
#endif // _GLFW_NO_DLOAD_GDI32
|
||||
|
||||
// winmm.dll shortcuts
|
||||
#ifndef _GLFW_NO_DLOAD_WINMM
|
||||
#define _glfw_joyGetDevCaps _glfwLibrary.Libs.joyGetDevCapsA
|
||||
#define _glfw_joyGetPos _glfwLibrary.Libs.joyGetPos
|
||||
#define _glfw_joyGetPosEx _glfwLibrary.Libs.joyGetPosEx
|
||||
#define _glfw_timeGetTime _glfwLibrary.Libs.timeGetTime
|
||||
#else
|
||||
#define _glfw_joyGetDevCaps joyGetDevCapsA
|
||||
#define _glfw_joyGetPos joyGetPos
|
||||
#define _glfw_joyGetPosEx joyGetPosEx
|
||||
#define _glfw_timeGetTime timeGetTime
|
||||
#endif // _GLFW_NO_DLOAD_WINMM
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Global variables (GLFW internals)
|
||||
//========================================================================
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Window structure
|
||||
//------------------------------------------------------------------------
|
||||
typedef struct _GLFWwin_struct _GLFWwin;
|
||||
|
||||
struct _GLFWwin_struct {
|
||||
|
||||
// ========= PLATFORM INDEPENDENT MANDATORY PART =========================
|
||||
|
||||
// User callback functions
|
||||
GLFWwindowsizefun WindowSizeCallback;
|
||||
GLFWwindowclosefun WindowCloseCallback;
|
||||
GLFWwindowrefreshfun WindowRefreshCallback;
|
||||
GLFWmousebuttonfun MouseButtonCallback;
|
||||
GLFWmouseposfun MousePosCallback;
|
||||
GLFWmousewheelfun MouseWheelCallback;
|
||||
GLFWkeyfun KeyCallback;
|
||||
GLFWcharfun CharCallback;
|
||||
|
||||
// User selected window settings
|
||||
int Fullscreen; // Fullscreen flag
|
||||
int MouseLock; // Mouse-lock flag
|
||||
int AutoPollEvents; // Auto polling flag
|
||||
int SysKeysDisabled; // System keys disabled flag
|
||||
int WindowNoResize; // Resize- and maximize gadgets disabled flag
|
||||
|
||||
// Window status & parameters
|
||||
int Opened; // Flag telling if window is opened or not
|
||||
int Active; // Application active flag
|
||||
int Iconified; // Window iconified flag
|
||||
int Width, Height; // Window width and heigth
|
||||
int Accelerated; // GL_TRUE if window is HW accelerated
|
||||
int RedBits;
|
||||
int GreenBits;
|
||||
int BlueBits;
|
||||
int AlphaBits;
|
||||
int DepthBits;
|
||||
int StencilBits;
|
||||
int AccumRedBits;
|
||||
int AccumGreenBits;
|
||||
int AccumBlueBits;
|
||||
int AccumAlphaBits;
|
||||
int AuxBuffers;
|
||||
int Stereo;
|
||||
int RefreshRate; // Vertical monitor refresh rate
|
||||
int Samples;
|
||||
|
||||
// Extensions & OpenGL version
|
||||
int Has_GL_SGIS_generate_mipmap;
|
||||
int Has_GL_ARB_texture_non_power_of_two;
|
||||
int GLVerMajor,GLVerMinor;
|
||||
|
||||
|
||||
// ========= PLATFORM SPECIFIC PART ======================================
|
||||
|
||||
// Platform specific window resources
|
||||
HDC DC; // Private GDI device context
|
||||
HGLRC RC; // Permanent rendering context
|
||||
HWND Wnd; // Window handle
|
||||
ATOM ClassAtom; // Window class atom
|
||||
int ModeID; // Mode ID for fullscreen mode
|
||||
HHOOK KeyboardHook; // Keyboard hook handle
|
||||
DWORD dwStyle; // Window styles used for window creation
|
||||
DWORD dwExStyle; // --"--
|
||||
|
||||
// Platform specific extensions (context specific)
|
||||
WGLSWAPINTERVALEXT_T SwapInterval;
|
||||
WGLCHOOSEPIXELFORMATARB_T ChoosePixelFormat;
|
||||
WGLGETPIXELFORMATATTRIBIVARB_T GetPixelFormatAttribiv;
|
||||
WGLGETEXTENSIONSSTRINGEXT_T GetExtensionsStringEXT;
|
||||
WGLGETEXTENSIONSSTRINGARB_T GetExtensionsStringARB;
|
||||
|
||||
// Various platform specific internal variables
|
||||
int OldMouseLock; // Old mouse-lock flag (used for remembering
|
||||
// mouse-lock state when iconifying)
|
||||
int OldMouseLockValid;
|
||||
int DesiredRefreshRate; // Desired vertical monitor refresh rate
|
||||
|
||||
};
|
||||
|
||||
GLFWGLOBAL _GLFWwin _glfwWin;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// User input status (most of this should go in _GLFWwin)
|
||||
//------------------------------------------------------------------------
|
||||
GLFWGLOBAL struct {
|
||||
|
||||
// ========= PLATFORM INDEPENDENT MANDATORY PART =========================
|
||||
|
||||
// Mouse status
|
||||
int MousePosX, MousePosY;
|
||||
int WheelPos;
|
||||
char MouseButton[ GLFW_MOUSE_BUTTON_LAST+1 ];
|
||||
|
||||
// Keyboard status
|
||||
char Key[ GLFW_KEY_LAST+1 ];
|
||||
int LastChar;
|
||||
|
||||
// User selected settings
|
||||
int StickyKeys;
|
||||
int StickyMouseButtons;
|
||||
int KeyRepeat;
|
||||
|
||||
|
||||
// ========= PLATFORM SPECIFIC PART ======================================
|
||||
|
||||
// Platform specific internal variables
|
||||
int MouseMoved, OldMouseX, OldMouseY;
|
||||
|
||||
} _glfwInput;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Library global data
|
||||
//------------------------------------------------------------------------
|
||||
GLFWGLOBAL struct {
|
||||
|
||||
// ========= PLATFORM SPECIFIC PART ======================================
|
||||
|
||||
HINSTANCE Instance; // Instance of the application
|
||||
|
||||
// Timer data
|
||||
struct {
|
||||
int HasPerformanceCounter;
|
||||
double Resolution;
|
||||
unsigned int t0_32;
|
||||
__int64 t0_64;
|
||||
} Timer;
|
||||
|
||||
// System information
|
||||
struct {
|
||||
int WinVer;
|
||||
int HasUnicode;
|
||||
DWORD ForegroundLockTimeout;
|
||||
} Sys;
|
||||
|
||||
#if !defined(_GLFW_NO_DLOAD_WINMM) || !defined(_GLFW_NO_DLOAD_GDI32)
|
||||
// Library handles and function pointers
|
||||
struct {
|
||||
#ifndef _GLFW_NO_DLOAD_GDI32
|
||||
// gdi32.dll
|
||||
HINSTANCE gdi32;
|
||||
CHOOSEPIXELFORMAT_T ChoosePixelFormat;
|
||||
DESCRIBEPIXELFORMAT_T DescribePixelFormat;
|
||||
GETPIXELFORMAT_T GetPixelFormat;
|
||||
SETPIXELFORMAT_T SetPixelFormat;
|
||||
SWAPBUFFERS_T SwapBuffers;
|
||||
#endif // _GLFW_NO_DLOAD_GDI32
|
||||
|
||||
// winmm.dll
|
||||
#ifndef _GLFW_NO_DLOAD_WINMM
|
||||
HINSTANCE winmm;
|
||||
JOYGETDEVCAPSA_T joyGetDevCapsA;
|
||||
JOYGETPOS_T joyGetPos;
|
||||
JOYGETPOSEX_T joyGetPosEx;
|
||||
TIMEGETTIME_T timeGetTime;
|
||||
#endif // _GLFW_NO_DLOAD_WINMM
|
||||
} Libs;
|
||||
#endif
|
||||
|
||||
} _glfwLibrary;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Thread record (one for each thread)
|
||||
//------------------------------------------------------------------------
|
||||
typedef struct _GLFWthread_struct _GLFWthread;
|
||||
|
||||
struct _GLFWthread_struct {
|
||||
|
||||
// ========= PLATFORM INDEPENDENT MANDATORY PART =========================
|
||||
|
||||
// Pointer to previous and next threads in linked list
|
||||
_GLFWthread *Previous, *Next;
|
||||
|
||||
// GLFW user side thread information
|
||||
GLFWthread ID;
|
||||
GLFWthreadfun Function;
|
||||
|
||||
// ========= PLATFORM SPECIFIC PART ======================================
|
||||
|
||||
// System side thread information
|
||||
HANDLE Handle;
|
||||
DWORD WinID;
|
||||
|
||||
};
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// General thread information
|
||||
//------------------------------------------------------------------------
|
||||
GLFWGLOBAL struct {
|
||||
|
||||
// ========= PLATFORM INDEPENDENT MANDATORY PART =========================
|
||||
|
||||
// Next thread ID to use (increments for every created thread)
|
||||
GLFWthread NextID;
|
||||
|
||||
// First thread in linked list (always the main thread)
|
||||
_GLFWthread First;
|
||||
|
||||
// ========= PLATFORM SPECIFIC PART ======================================
|
||||
|
||||
// Critical section lock
|
||||
CRITICAL_SECTION CriticalSection;
|
||||
|
||||
} _glfwThrd;
|
||||
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Macros for encapsulating critical code sections (i.e. making parts
|
||||
// of GLFW thread safe)
|
||||
//========================================================================
|
||||
|
||||
// Thread list management
|
||||
#define ENTER_THREAD_CRITICAL_SECTION \
|
||||
EnterCriticalSection( &_glfwThrd.CriticalSection );
|
||||
#define LEAVE_THREAD_CRITICAL_SECTION \
|
||||
LeaveCriticalSection( &_glfwThrd.CriticalSection );
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Various Windows version constants
|
||||
//========================================================================
|
||||
|
||||
#define _GLFW_WIN_UNKNOWN 0x0000 // Earlier than 95 or NT4
|
||||
#define _GLFW_WIN_95 0x0001
|
||||
#define _GLFW_WIN_98 0x0002
|
||||
#define _GLFW_WIN_ME 0x0003
|
||||
#define _GLFW_WIN_UNKNOWN_9x 0x0004 // Later than ME
|
||||
#define _GLFW_WIN_NT4 0x0101
|
||||
#define _GLFW_WIN_2K 0x0102
|
||||
#define _GLFW_WIN_XP 0x0103
|
||||
#define _GLFW_WIN_NET_SERVER 0x0104
|
||||
#define _GLFW_WIN_UNKNOWN_NT 0x0105 // Later than .NET Server
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Prototypes for platform specific internal functions
|
||||
//========================================================================
|
||||
|
||||
// Time
|
||||
void _glfwInitTimer( void );
|
||||
|
||||
// Fullscreen support
|
||||
int _glfwGetClosestVideoModeBPP( int *w, int *h, int *bpp, int *refresh );
|
||||
int _glfwGetClosestVideoMode( int *w, int *h, int *r, int *g, int *b, int *refresh );
|
||||
void _glfwSetVideoModeMODE( int mode );
|
||||
void _glfwSetVideoMode( int *w, int *h, int r, int g, int b, int refresh );
|
||||
|
||||
|
||||
#endif // _platform_h_
|
60
libs/glfw/lib/win32/win32_dllmain.c
Normal file
60
libs/glfw/lib/win32/win32_dllmain.c
Normal file
@ -0,0 +1,60 @@
|
||||
//========================================================================
|
||||
// GLFW - An OpenGL framework
|
||||
// File: win32_dllmain.c
|
||||
// Platform: Windows
|
||||
// API version: 2.6
|
||||
// WWW: http://glfw.sourceforge.net
|
||||
//------------------------------------------------------------------------
|
||||
// Copyright (c) 2002-2006 Camilla Berglund
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would
|
||||
// be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not
|
||||
// be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
#if defined(GLFW_BUILD_DLL)
|
||||
|
||||
//========================================================================
|
||||
// DllMain()
|
||||
//========================================================================
|
||||
|
||||
int WINAPI DllMain( HINSTANCE hinst, unsigned long reason, void *x )
|
||||
{
|
||||
// NOTE: Some compilers complains about hinst and x never being used -
|
||||
// never mind that (we don't want to use them)!
|
||||
|
||||
switch( reason )
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
// Initializations
|
||||
//glfwInit(); // We don't want to do that now!
|
||||
break;
|
||||
case DLL_PROCESS_DETACH:
|
||||
// Do some cleanup
|
||||
glfwTerminate();
|
||||
break;
|
||||
};
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif // GLFW_BUILD_DLL
|
155
libs/glfw/lib/win32/win32_enable.c
Normal file
155
libs/glfw/lib/win32/win32_enable.c
Normal file
@ -0,0 +1,155 @@
|
||||
//========================================================================
|
||||
// GLFW - An OpenGL framework
|
||||
// File: win32_enable.c
|
||||
// Platform: Windows
|
||||
// API version: 2.6
|
||||
// WWW: http://glfw.sourceforge.net
|
||||
//------------------------------------------------------------------------
|
||||
// Copyright (c) 2002-2006 Camilla Berglund
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would
|
||||
// be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not
|
||||
// be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
//************************************************************************
|
||||
//**** GLFW internal functions ****
|
||||
//************************************************************************
|
||||
|
||||
//========================================================================
|
||||
// _glfwLLKeyboardProc() - Low level keyboard callback function (used to
|
||||
// disable system keys under Windows NT).
|
||||
//========================================================================
|
||||
|
||||
LRESULT CALLBACK _glfwLLKeyboardProc( int nCode, WPARAM wParam,
|
||||
LPARAM lParam )
|
||||
{
|
||||
BOOL syskeys = 0;
|
||||
PKBDLLHOOKSTRUCT p;
|
||||
|
||||
// We are only looking for keyboard events - interpret lParam as a
|
||||
// pointer to a KBDLLHOOKSTRUCT
|
||||
p = (PKBDLLHOOKSTRUCT) lParam;
|
||||
|
||||
// If nCode == HC_ACTION, then we have a keyboard event
|
||||
if( nCode == HC_ACTION )
|
||||
{
|
||||
switch( wParam )
|
||||
{
|
||||
case WM_KEYDOWN:
|
||||
case WM_SYSKEYDOWN:
|
||||
case WM_KEYUP:
|
||||
case WM_SYSKEYUP:
|
||||
// Detect: ALT+TAB, ALT+ESC, ALT+F4, CTRL+ESC,
|
||||
// LWIN, RWIN, APPS (mysterious menu key)
|
||||
syskeys = ( p->vkCode == VK_TAB &&
|
||||
p->flags & LLKHF_ALTDOWN ) ||
|
||||
( p->vkCode == VK_ESCAPE &&
|
||||
p->flags & LLKHF_ALTDOWN ) ||
|
||||
( p->vkCode == VK_F4 &&
|
||||
p->flags & LLKHF_ALTDOWN ) ||
|
||||
( p->vkCode == VK_ESCAPE &&
|
||||
(GetKeyState(VK_CONTROL) & 0x8000)) ||
|
||||
p->vkCode == VK_LWIN ||
|
||||
p->vkCode == VK_RWIN ||
|
||||
p->vkCode == VK_APPS;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Was it a system key combination (e.g. ALT+TAB)?
|
||||
if( syskeys )
|
||||
{
|
||||
// Pass the key event to our window message loop
|
||||
if( _glfwWin.Opened )
|
||||
{
|
||||
PostMessage( _glfwWin.Wnd, (UINT) wParam, p->vkCode, 0 );
|
||||
}
|
||||
|
||||
// We've taken care of it - don't let the system know about this
|
||||
// key event
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// It's a harmless key press, let the system deal with it
|
||||
return CallNextHookEx( _glfwWin.KeyboardHook, nCode, wParam,
|
||||
lParam );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//************************************************************************
|
||||
//**** Platform implementation functions ****
|
||||
//************************************************************************
|
||||
|
||||
//========================================================================
|
||||
// _glfwPlatformEnableSystemKeys() - Enable system keys
|
||||
// _glfwPlatformDisableSystemKeys() - Disable system keys
|
||||
//========================================================================
|
||||
|
||||
void _glfwPlatformEnableSystemKeys( void )
|
||||
{
|
||||
BOOL bOld;
|
||||
|
||||
// Use different methods depending on operating system version
|
||||
if( _glfwLibrary.Sys.WinVer >= _GLFW_WIN_NT4 )
|
||||
{
|
||||
if( _glfwWin.KeyboardHook != NULL )
|
||||
{
|
||||
UnhookWindowsHookEx( _glfwWin.KeyboardHook );
|
||||
_glfwWin.KeyboardHook = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
(void) SystemParametersInfo( SPI_SETSCREENSAVERRUNNING, FALSE,
|
||||
&bOld, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
void _glfwPlatformDisableSystemKeys( void )
|
||||
{
|
||||
BOOL bOld;
|
||||
|
||||
// Use different methods depending on operating system version
|
||||
if( _glfwLibrary.Sys.WinVer >= _GLFW_WIN_NT4 )
|
||||
{
|
||||
// Under Windows NT, install a low level keyboard hook
|
||||
_glfwWin.KeyboardHook = SetWindowsHookEx( WH_KEYBOARD_LL,
|
||||
_glfwLLKeyboardProc,
|
||||
_glfwLibrary.Instance,
|
||||
0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Under Windows 95/98/ME, fool Windows that a screensaver
|
||||
// is running => prevents ALT+TAB, CTRL+ESC and CTRL+ALT+DEL
|
||||
(void) SystemParametersInfo( SPI_SETSCREENSAVERRUNNING, TRUE,
|
||||
&bOld, 0 );
|
||||
}
|
||||
}
|
||||
|
317
libs/glfw/lib/win32/win32_fullscreen.c
Normal file
317
libs/glfw/lib/win32/win32_fullscreen.c
Normal file
@ -0,0 +1,317 @@
|
||||
//========================================================================
|
||||
// GLFW - An OpenGL framework
|
||||
// File: win32_fullscreen.c
|
||||
// Platform: Windows
|
||||
// API version: 2.6
|
||||
// WWW: http://glfw.sourceforge.net
|
||||
//------------------------------------------------------------------------
|
||||
// Copyright (c) 2002-2006 Camilla Berglund
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would
|
||||
// be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not
|
||||
// be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
//************************************************************************
|
||||
//**** GLFW internal functions ****
|
||||
//************************************************************************
|
||||
|
||||
//========================================================================
|
||||
// _glfwBPP2RGB() - Convert BPP to RGB bits (based on "best guess")
|
||||
//========================================================================
|
||||
|
||||
static void _glfwBPP2RGB( int bpp, int *r, int *g, int *b )
|
||||
{
|
||||
int delta;
|
||||
|
||||
// Special case: BPP = 32
|
||||
if( bpp == 32 ) bpp = 24;
|
||||
|
||||
// Convert "bits per pixel" to red, green & blue sizes
|
||||
*r = *g = *b = bpp / 3;
|
||||
delta = bpp - (*r * 3);
|
||||
if( delta >= 1 )
|
||||
{
|
||||
*g = *g + 1;
|
||||
}
|
||||
if( delta == 2 )
|
||||
{
|
||||
*r = *r + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// _glfwGetClosestVideoModeBPP()
|
||||
//========================================================================
|
||||
|
||||
int _glfwGetClosestVideoModeBPP( int *w, int *h, int *bpp, int *refresh )
|
||||
{
|
||||
int mode, bestmode, match, bestmatch, rr, bestrr, success;
|
||||
DEVMODE dm;
|
||||
|
||||
// Find best match
|
||||
bestmatch = 0x7fffffff;
|
||||
bestrr = 0x7fffffff;
|
||||
mode = bestmode = 0;
|
||||
do
|
||||
{
|
||||
dm.dmSize = sizeof( DEVMODE );
|
||||
success = EnumDisplaySettings( NULL, mode, &dm );
|
||||
if( success )
|
||||
{
|
||||
match = dm.dmBitsPerPel - *bpp;
|
||||
if( match < 0 ) match = -match;
|
||||
match = ( match << 25 ) |
|
||||
( (dm.dmPelsWidth - *w) *
|
||||
(dm.dmPelsWidth - *w) +
|
||||
(dm.dmPelsHeight - *h) *
|
||||
(dm.dmPelsHeight - *h) );
|
||||
if( match < bestmatch )
|
||||
{
|
||||
bestmatch = match;
|
||||
bestmode = mode;
|
||||
bestrr = (dm.dmDisplayFrequency - *refresh) *
|
||||
(dm.dmDisplayFrequency - *refresh);
|
||||
}
|
||||
else if( match == bestmatch && *refresh > 0 )
|
||||
{
|
||||
rr = (dm.dmDisplayFrequency - *refresh) *
|
||||
(dm.dmDisplayFrequency - *refresh);
|
||||
if( rr < bestrr )
|
||||
{
|
||||
bestmatch = match;
|
||||
bestmode = mode;
|
||||
bestrr = rr;
|
||||
}
|
||||
}
|
||||
}
|
||||
mode ++;
|
||||
}
|
||||
while( success );
|
||||
|
||||
// Get the parameters for the best matching display mode
|
||||
dm.dmSize = sizeof( DEVMODE );
|
||||
(void) EnumDisplaySettings( NULL, bestmode, &dm );
|
||||
|
||||
// Fill out actual width and height
|
||||
*w = dm.dmPelsWidth;
|
||||
*h = dm.dmPelsHeight;
|
||||
|
||||
// Return bits per pixel
|
||||
*bpp = dm.dmBitsPerPel;
|
||||
|
||||
// Return vertical refresh rate
|
||||
*refresh = dm.dmDisplayFrequency;
|
||||
|
||||
return bestmode;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// _glfwGetClosestVideoMode()
|
||||
//========================================================================
|
||||
|
||||
int _glfwGetClosestVideoMode( int *w, int *h, int *r, int *g, int *b,
|
||||
int *refresh )
|
||||
{
|
||||
int bpp, bestmode;
|
||||
|
||||
// Colorbits = sum of red/green/blue bits
|
||||
bpp = *r + *g + *b;
|
||||
|
||||
// If colorbits < 15 (e.g. 0) or >= 24, default to 32 bpp
|
||||
if( bpp < 15 || bpp >= 24 )
|
||||
{
|
||||
bpp = 32;
|
||||
}
|
||||
|
||||
// Find best match
|
||||
bestmode = _glfwGetClosestVideoModeBPP( w, h, &bpp, refresh );
|
||||
|
||||
// Convert "bits per pixel" to red, green & blue sizes
|
||||
_glfwBPP2RGB( bpp, r, g, b );
|
||||
|
||||
return bestmode;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Change the current video mode
|
||||
//========================================================================
|
||||
|
||||
void _glfwSetVideoModeMODE( int mode )
|
||||
{
|
||||
DEVMODE dm;
|
||||
int success;
|
||||
|
||||
// Get the parameters for the best matching display mode
|
||||
dm.dmSize = sizeof( DEVMODE );
|
||||
(void) EnumDisplaySettings( NULL, mode, &dm );
|
||||
|
||||
// Set which fields we want to specify
|
||||
dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
|
||||
|
||||
// Do we have a prefered refresh rate?
|
||||
if( _glfwWin.DesiredRefreshRate > 0 )
|
||||
{
|
||||
dm.dmFields = dm.dmFields | DM_DISPLAYFREQUENCY;
|
||||
dm.dmDisplayFrequency = _glfwWin.DesiredRefreshRate;
|
||||
}
|
||||
|
||||
// Change display setting
|
||||
dm.dmSize = sizeof( DEVMODE );
|
||||
success = ChangeDisplaySettings( &dm, CDS_FULLSCREEN );
|
||||
|
||||
// If the mode change was not possible, query the current display
|
||||
// settings (we'll use the desktop resolution for fullscreen mode)
|
||||
if( success == DISP_CHANGE_SUCCESSFUL )
|
||||
{
|
||||
_glfwWin.ModeID = mode;
|
||||
}
|
||||
else
|
||||
{
|
||||
_glfwWin.ModeID = ENUM_REGISTRY_SETTINGS;
|
||||
EnumDisplaySettings( NULL, ENUM_REGISTRY_SETTINGS, &dm );
|
||||
}
|
||||
|
||||
// Set the window size to that of the display mode
|
||||
_glfwWin.Width = dm.dmPelsWidth;
|
||||
_glfwWin.Height = dm.dmPelsHeight;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// _glfwSetVideoMode() - Change the current video mode
|
||||
//========================================================================
|
||||
|
||||
void _glfwSetVideoMode( int *w, int *h, int r, int g, int b, int refresh )
|
||||
{
|
||||
int bestmode;
|
||||
|
||||
// Find a best match mode
|
||||
bestmode = _glfwGetClosestVideoMode( w, h, &r, &g, &b, &refresh );
|
||||
|
||||
// Change mode
|
||||
_glfwSetVideoModeMODE( bestmode );
|
||||
}
|
||||
|
||||
|
||||
//************************************************************************
|
||||
//**** GLFW user functions ****
|
||||
//************************************************************************
|
||||
|
||||
//========================================================================
|
||||
// _glfwPlatformGetVideoModes() - Get a list of available video modes
|
||||
//========================================================================
|
||||
|
||||
int _glfwPlatformGetVideoModes( GLFWvidmode *list, int maxcount )
|
||||
{
|
||||
int count, success, mode, i, j;
|
||||
int m1, m2, bpp, r, g, b;
|
||||
DEVMODE dm;
|
||||
|
||||
// Loop through all video modes and extract all the UNIQUE modes
|
||||
count = 0;
|
||||
mode = 0;
|
||||
do
|
||||
{
|
||||
// Get video mode properties
|
||||
dm.dmSize = sizeof( DEVMODE );
|
||||
success = EnumDisplaySettings( NULL, mode, &dm );
|
||||
|
||||
// Is it a valid mode? (only list depths >= 15 bpp)
|
||||
if( success && dm.dmBitsPerPel >= 15 )
|
||||
{
|
||||
// Convert to RGB, and back to bpp ("mask out" alpha bits etc)
|
||||
_glfwBPP2RGB( dm.dmBitsPerPel, &r, &g, &b );
|
||||
bpp = r + g + b;
|
||||
|
||||
// Mode "code" for this mode
|
||||
m1 = (bpp << 25) | (dm.dmPelsWidth * dm.dmPelsHeight);
|
||||
|
||||
// Insert mode in list (sorted), and avoid duplicates
|
||||
for( i = 0; i < count; i ++ )
|
||||
{
|
||||
// Mode "code" for already listed mode
|
||||
bpp = list[i].RedBits + list[i].GreenBits +
|
||||
list[i].BlueBits;
|
||||
m2 = (bpp << 25) | (list[i].Width * list[i].Height);
|
||||
if( m1 <= m2 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// New entry at the end of the list?
|
||||
if( i >= count )
|
||||
{
|
||||
list[count].Width = dm.dmPelsWidth;
|
||||
list[count].Height = dm.dmPelsHeight;
|
||||
list[count].RedBits = r;
|
||||
list[count].GreenBits = g;
|
||||
list[count].BlueBits = b;
|
||||
count ++;
|
||||
}
|
||||
// Insert new entry in the list?
|
||||
else if( m1 < m2 )
|
||||
{
|
||||
for( j = count; j > i; j -- )
|
||||
{
|
||||
list[j] = list[j-1];
|
||||
}
|
||||
list[i].Width = dm.dmPelsWidth;
|
||||
list[i].Height = dm.dmPelsHeight;
|
||||
list[i].RedBits = r;
|
||||
list[i].GreenBits = g;
|
||||
list[i].BlueBits = b;
|
||||
count ++;
|
||||
}
|
||||
}
|
||||
mode ++;
|
||||
}
|
||||
while( success && (count < maxcount) );
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// _glfwPlatformGetDesktopMode() - Get the desktop video mode
|
||||
//========================================================================
|
||||
|
||||
void _glfwPlatformGetDesktopMode( GLFWvidmode *mode )
|
||||
{
|
||||
DEVMODE dm;
|
||||
|
||||
// Get desktop display mode
|
||||
dm.dmSize = sizeof( DEVMODE );
|
||||
(void) EnumDisplaySettings( NULL, ENUM_REGISTRY_SETTINGS, &dm );
|
||||
|
||||
// Return desktop mode parameters
|
||||
mode->Width = dm.dmPelsWidth;
|
||||
mode->Height = dm.dmPelsHeight;
|
||||
_glfwBPP2RGB( dm.dmBitsPerPel, &mode->RedBits, &mode->GreenBits,
|
||||
&mode->BlueBits );
|
||||
}
|
||||
|
||||
|
85
libs/glfw/lib/win32/win32_glext.c
Normal file
85
libs/glfw/lib/win32/win32_glext.c
Normal file
@ -0,0 +1,85 @@
|
||||
//========================================================================
|
||||
// GLFW - An OpenGL framework
|
||||
// File: win32_glext.c
|
||||
// Platform: Windows
|
||||
// API version: 2.6
|
||||
// WWW: http://glfw.sourceforge.net
|
||||
//------------------------------------------------------------------------
|
||||
// Copyright (c) 2002-2006 Camilla Berglund
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would
|
||||
// be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not
|
||||
// be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
//************************************************************************
|
||||
//**** Platform implementation functions ****
|
||||
//************************************************************************
|
||||
|
||||
//========================================================================
|
||||
// Check if an OpenGL extension is available at runtime (Windows version checks
|
||||
// for WGL extensions)
|
||||
//========================================================================
|
||||
|
||||
int _glfwPlatformExtensionSupported( const char *extension )
|
||||
{
|
||||
const GLubyte *extensions;
|
||||
|
||||
// Try wglGetExtensionsStringEXT
|
||||
if( _glfwWin.GetExtensionsStringEXT != NULL )
|
||||
{
|
||||
extensions = (GLubyte *) _glfwWin.GetExtensionsStringEXT();
|
||||
if( extensions != NULL )
|
||||
{
|
||||
if( _glfwStringInExtensionString( extension, extensions ) )
|
||||
{
|
||||
return GL_TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Try wglGetExtensionsStringARB
|
||||
if( _glfwWin.GetExtensionsStringARB != NULL )
|
||||
{
|
||||
extensions = (GLubyte *) _glfwWin.GetExtensionsStringARB( _glfwWin.DC );
|
||||
if( extensions != NULL )
|
||||
{
|
||||
if( _glfwStringInExtensionString( extension, extensions ) )
|
||||
{
|
||||
return GL_TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Get the function pointer to an OpenGL function
|
||||
//========================================================================
|
||||
|
||||
void * _glfwPlatformGetProcAddress( const char *procname )
|
||||
{
|
||||
return (void *) wglGetProcAddress( procname );
|
||||
}
|
||||
|
356
libs/glfw/lib/win32/win32_init.c
Normal file
356
libs/glfw/lib/win32/win32_init.c
Normal file
@ -0,0 +1,356 @@
|
||||
//========================================================================
|
||||
// GLFW - An OpenGL framework
|
||||
// File: win32_init.c
|
||||
// Platform: Windows
|
||||
// API version: 2.6
|
||||
// WWW: http://glfw.sourceforge.net
|
||||
//------------------------------------------------------------------------
|
||||
// Copyright (c) 2002-2006 Camilla Berglund
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would
|
||||
// be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not
|
||||
// be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
// With the Borland C++ compiler, we want to disable FPU exceptions
|
||||
#ifdef __BORLANDC__
|
||||
#include <float.h>
|
||||
#endif // __BORLANDC__
|
||||
|
||||
|
||||
|
||||
//************************************************************************
|
||||
//**** GLFW internal functions ****
|
||||
//************************************************************************
|
||||
|
||||
//========================================================================
|
||||
// _glfwInitLibraries() - Load necessary libraries (DLLs)
|
||||
//========================================================================
|
||||
|
||||
static int _glfwInitLibraries( void )
|
||||
{
|
||||
// gdi32.dll (OpenGL pixel format functions & SwapBuffers)
|
||||
#ifndef _GLFW_NO_DLOAD_GDI32
|
||||
_glfwLibrary.Libs.gdi32 = LoadLibrary( "gdi32.dll" );
|
||||
if( _glfwLibrary.Libs.gdi32 != NULL )
|
||||
{
|
||||
_glfwLibrary.Libs.ChoosePixelFormat = (CHOOSEPIXELFORMAT_T)
|
||||
GetProcAddress( _glfwLibrary.Libs.gdi32, "ChoosePixelFormat" );
|
||||
_glfwLibrary.Libs.DescribePixelFormat = (DESCRIBEPIXELFORMAT_T)
|
||||
GetProcAddress( _glfwLibrary.Libs.gdi32, "DescribePixelFormat" );
|
||||
_glfwLibrary.Libs.GetPixelFormat = (GETPIXELFORMAT_T)
|
||||
GetProcAddress( _glfwLibrary.Libs.gdi32, "GetPixelFormat" );
|
||||
_glfwLibrary.Libs.SetPixelFormat = (SETPIXELFORMAT_T)
|
||||
GetProcAddress( _glfwLibrary.Libs.gdi32, "SetPixelFormat" );
|
||||
_glfwLibrary.Libs.SwapBuffers = (SWAPBUFFERS_T)
|
||||
GetProcAddress( _glfwLibrary.Libs.gdi32, "SwapBuffers" );
|
||||
if( _glfwLibrary.Libs.ChoosePixelFormat == NULL ||
|
||||
_glfwLibrary.Libs.DescribePixelFormat == NULL ||
|
||||
_glfwLibrary.Libs.GetPixelFormat == NULL ||
|
||||
_glfwLibrary.Libs.SetPixelFormat == NULL ||
|
||||
_glfwLibrary.Libs.SwapBuffers == NULL )
|
||||
{
|
||||
FreeLibrary( _glfwLibrary.Libs.gdi32 );
|
||||
_glfwLibrary.Libs.gdi32 = NULL;
|
||||
return GL_FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return GL_FALSE;
|
||||
}
|
||||
#endif // _GLFW_NO_DLOAD_GDI32
|
||||
|
||||
// winmm.dll (for joystick and timer support)
|
||||
#ifndef _GLFW_NO_DLOAD_WINMM
|
||||
_glfwLibrary.Libs.winmm = LoadLibrary( "winmm.dll" );
|
||||
if( _glfwLibrary.Libs.winmm != NULL )
|
||||
{
|
||||
_glfwLibrary.Libs.joyGetDevCapsA = (JOYGETDEVCAPSA_T)
|
||||
GetProcAddress( _glfwLibrary.Libs.winmm, "joyGetDevCapsA" );
|
||||
_glfwLibrary.Libs.joyGetPos = (JOYGETPOS_T)
|
||||
GetProcAddress( _glfwLibrary.Libs.winmm, "joyGetPos" );
|
||||
_glfwLibrary.Libs.joyGetPosEx = (JOYGETPOSEX_T)
|
||||
GetProcAddress( _glfwLibrary.Libs.winmm, "joyGetPosEx" );
|
||||
_glfwLibrary.Libs.timeGetTime = (TIMEGETTIME_T)
|
||||
GetProcAddress( _glfwLibrary.Libs.winmm, "timeGetTime" );
|
||||
if( _glfwLibrary.Libs.joyGetDevCapsA == NULL ||
|
||||
_glfwLibrary.Libs.joyGetPos == NULL ||
|
||||
_glfwLibrary.Libs.joyGetPosEx == NULL ||
|
||||
_glfwLibrary.Libs.timeGetTime == NULL )
|
||||
{
|
||||
FreeLibrary( _glfwLibrary.Libs.winmm );
|
||||
_glfwLibrary.Libs.winmm = NULL;
|
||||
return GL_FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return GL_FALSE;
|
||||
}
|
||||
#endif // _GLFW_NO_DLOAD_WINMM
|
||||
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// _glfwFreeLibraries() - Unload used libraries (DLLs)
|
||||
//========================================================================
|
||||
|
||||
static void _glfwFreeLibraries( void )
|
||||
{
|
||||
// gdi32.dll
|
||||
#ifndef _GLFW_NO_DLOAD_GDI32
|
||||
if( _glfwLibrary.Libs.gdi32 != NULL )
|
||||
{
|
||||
FreeLibrary( _glfwLibrary.Libs.gdi32 );
|
||||
_glfwLibrary.Libs.gdi32 = NULL;
|
||||
}
|
||||
#endif // _GLFW_NO_DLOAD_GDI32
|
||||
|
||||
// winmm.dll
|
||||
#ifndef _GLFW_NO_DLOAD_WINMM
|
||||
if( _glfwLibrary.Libs.winmm != NULL )
|
||||
{
|
||||
FreeLibrary( _glfwLibrary.Libs.winmm );
|
||||
_glfwLibrary.Libs.winmm = NULL;
|
||||
}
|
||||
#endif // _GLFW_NO_DLOAD_WINMM
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// _glfwInitThreads() - Initialize GLFW thread package
|
||||
//========================================================================
|
||||
|
||||
static void _glfwInitThreads( void )
|
||||
{
|
||||
// Initialize critical section handle
|
||||
InitializeCriticalSection( &_glfwThrd.CriticalSection );
|
||||
|
||||
// The first thread (the main thread) has ID 0
|
||||
_glfwThrd.NextID = 0;
|
||||
|
||||
// Fill out information about the main thread (this thread)
|
||||
_glfwThrd.First.ID = _glfwThrd.NextID ++;
|
||||
_glfwThrd.First.Function = NULL;
|
||||
_glfwThrd.First.Handle = GetCurrentThread();
|
||||
_glfwThrd.First.WinID = GetCurrentThreadId();
|
||||
_glfwThrd.First.Previous = NULL;
|
||||
_glfwThrd.First.Next = NULL;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// _glfwTerminateThreads() - Terminate GLFW thread package
|
||||
//========================================================================
|
||||
|
||||
static void _glfwTerminateThreads( void )
|
||||
{
|
||||
_GLFWthread *t, *t_next;
|
||||
|
||||
// Enter critical section
|
||||
ENTER_THREAD_CRITICAL_SECTION
|
||||
|
||||
// Kill all threads (NOTE: THE USER SHOULD WAIT FOR ALL THREADS TO
|
||||
// DIE, _BEFORE_ CALLING glfwTerminate()!!!)
|
||||
t = _glfwThrd.First.Next;
|
||||
while( t != NULL )
|
||||
{
|
||||
// Get pointer to next thread
|
||||
t_next = t->Next;
|
||||
|
||||
// Simply murder the process, no mercy!
|
||||
if( TerminateThread( t->Handle, 0 ) )
|
||||
{
|
||||
// Close thread handle
|
||||
CloseHandle( t->Handle );
|
||||
|
||||
// Free memory allocated for this thread
|
||||
free( (void *) t );
|
||||
}
|
||||
|
||||
// Select next thread in list
|
||||
t = t_next;
|
||||
}
|
||||
|
||||
// Leave critical section
|
||||
LEAVE_THREAD_CRITICAL_SECTION
|
||||
|
||||
// Delete critical section handle
|
||||
DeleteCriticalSection( &_glfwThrd.CriticalSection );
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// _glfwTerminate_atexit() - Terminate GLFW when exiting application
|
||||
//========================================================================
|
||||
|
||||
void _glfwTerminate_atexit( void )
|
||||
{
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//************************************************************************
|
||||
//**** Platform implementation functions ****
|
||||
//************************************************************************
|
||||
|
||||
//========================================================================
|
||||
// _glfwPlatformInit() - Initialize various GLFW state
|
||||
//========================================================================
|
||||
|
||||
int _glfwPlatformInit( void )
|
||||
{
|
||||
OSVERSIONINFO osi;
|
||||
|
||||
// To make SetForegroundWindow() work as we want, we need to fiddle
|
||||
// with the FOREGROUNDLOCKTIMEOUT system setting (we do this as early
|
||||
// as possible in the hope of still being the foreground process)
|
||||
SystemParametersInfo( SPI_GETFOREGROUNDLOCKTIMEOUT, 0,
|
||||
&_glfwLibrary.Sys.ForegroundLockTimeout, 0 );
|
||||
SystemParametersInfo( SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID)0,
|
||||
SPIF_SENDCHANGE );
|
||||
|
||||
// Check which OS version we are running
|
||||
osi.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
|
||||
GetVersionEx( &osi );
|
||||
_glfwLibrary.Sys.WinVer = _GLFW_WIN_UNKNOWN;
|
||||
if( osi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS )
|
||||
{
|
||||
if( osi.dwMajorVersion == 4 && osi.dwMinorVersion < 10 )
|
||||
{
|
||||
_glfwLibrary.Sys.WinVer = _GLFW_WIN_95;
|
||||
}
|
||||
else if( osi.dwMajorVersion == 4 && osi.dwMinorVersion < 90 )
|
||||
{
|
||||
_glfwLibrary.Sys.WinVer = _GLFW_WIN_98;
|
||||
}
|
||||
else if( osi.dwMajorVersion == 4 && osi.dwMinorVersion == 90 )
|
||||
{
|
||||
_glfwLibrary.Sys.WinVer = _GLFW_WIN_ME;
|
||||
}
|
||||
else if( osi.dwMajorVersion >= 4 )
|
||||
{
|
||||
_glfwLibrary.Sys.WinVer = _GLFW_WIN_UNKNOWN_9x;
|
||||
}
|
||||
}
|
||||
else if( osi.dwPlatformId == VER_PLATFORM_WIN32_NT )
|
||||
{
|
||||
if( osi.dwMajorVersion == 4 && osi.dwMinorVersion == 0 )
|
||||
{
|
||||
_glfwLibrary.Sys.WinVer = _GLFW_WIN_NT4;
|
||||
}
|
||||
else if( osi.dwMajorVersion == 5 && osi.dwMinorVersion == 0 )
|
||||
{
|
||||
_glfwLibrary.Sys.WinVer = _GLFW_WIN_2K;
|
||||
}
|
||||
else if( osi.dwMajorVersion == 5 && osi.dwMinorVersion == 1 )
|
||||
{
|
||||
_glfwLibrary.Sys.WinVer = _GLFW_WIN_XP;
|
||||
}
|
||||
else if( osi.dwMajorVersion == 5 && osi.dwMinorVersion == 2 )
|
||||
{
|
||||
_glfwLibrary.Sys.WinVer = _GLFW_WIN_NET_SERVER;
|
||||
}
|
||||
else if( osi.dwMajorVersion >= 5 )
|
||||
{
|
||||
_glfwLibrary.Sys.WinVer = _GLFW_WIN_UNKNOWN_NT;
|
||||
}
|
||||
}
|
||||
|
||||
// Do we have Unicode support?
|
||||
if( _glfwLibrary.Sys.WinVer >= _GLFW_WIN_NT4 )
|
||||
{
|
||||
// Windows NT/2000/XP/.NET has Unicode support
|
||||
_glfwLibrary.Sys.HasUnicode = GL_TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Windows 9x/ME does not have Unicode support
|
||||
_glfwLibrary.Sys.HasUnicode = GL_FALSE;
|
||||
}
|
||||
|
||||
// Load libraries (DLLs)
|
||||
if( !_glfwInitLibraries() )
|
||||
{
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
// With the Borland C++ compiler, we want to disable FPU exceptions
|
||||
// (this is recommended for OpenGL applications under Windows)
|
||||
#ifdef __BORLANDC__
|
||||
_control87( MCW_EM, MCW_EM );
|
||||
#endif
|
||||
|
||||
// Retrieve GLFW instance handle
|
||||
_glfwLibrary.Instance = GetModuleHandle( NULL );
|
||||
|
||||
// System keys are not disabled
|
||||
_glfwWin.KeyboardHook = NULL;
|
||||
|
||||
// Initialise thread package
|
||||
_glfwInitThreads();
|
||||
|
||||
// Install atexit() routine
|
||||
atexit( _glfwTerminate_atexit );
|
||||
|
||||
// Start the timer
|
||||
_glfwInitTimer();
|
||||
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// _glfwPlatformTerminate() - Close window and kill all threads
|
||||
//========================================================================
|
||||
|
||||
int _glfwPlatformTerminate( void )
|
||||
{
|
||||
// Only the main thread is allowed to do this...
|
||||
if( GetCurrentThreadId() != _glfwThrd.First.WinID )
|
||||
{
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
// Close OpenGL window
|
||||
glfwCloseWindow();
|
||||
|
||||
// Kill thread package
|
||||
_glfwTerminateThreads();
|
||||
|
||||
// Enable system keys again (if they were disabled)
|
||||
glfwEnable( GLFW_SYSTEM_KEYS );
|
||||
|
||||
// Unload libraries (DLLs)
|
||||
_glfwFreeLibraries();
|
||||
|
||||
// Restore FOREGROUNDLOCKTIMEOUT system setting
|
||||
SystemParametersInfo( SPI_SETFOREGROUNDLOCKTIMEOUT, 0,
|
||||
(LPVOID)_glfwLibrary.Sys.ForegroundLockTimeout,
|
||||
SPIF_SENDCHANGE );
|
||||
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
234
libs/glfw/lib/win32/win32_joystick.c
Normal file
234
libs/glfw/lib/win32/win32_joystick.c
Normal file
@ -0,0 +1,234 @@
|
||||
//========================================================================
|
||||
// GLFW - An OpenGL framework
|
||||
// File: win32_joystick.c
|
||||
// Platform: Windows
|
||||
// API version: 2.6
|
||||
// WWW: http://glfw.sourceforge.net
|
||||
//------------------------------------------------------------------------
|
||||
// Copyright (c) 2002-2006 Camilla Berglund
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would
|
||||
// be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not
|
||||
// be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
//************************************************************************
|
||||
//**** GLFW internal functions ****
|
||||
//************************************************************************
|
||||
|
||||
//========================================================================
|
||||
// _glfwJoystickPresent() - Return GL_TRUE if joystick is present,
|
||||
// else return GL_FALSE.
|
||||
//========================================================================
|
||||
|
||||
static int _glfwJoystickPresent( int joy )
|
||||
{
|
||||
JOYINFO ji;
|
||||
|
||||
// Windows NT 4.0 MMSYSTEM only supports 2 sticks (other Windows
|
||||
// versions support 16 sticks)
|
||||
if( _glfwLibrary.Sys.WinVer == _GLFW_WIN_NT4 && joy > GLFW_JOYSTICK_2 )
|
||||
{
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
// Is it a valid stick ID (Windows don't support more than 16 sticks)?
|
||||
if( joy < GLFW_JOYSTICK_1 || joy > GLFW_JOYSTICK_16 )
|
||||
{
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
// Is the joystick present?
|
||||
if( _glfw_joyGetPos( joy - GLFW_JOYSTICK_1, &ji ) != JOYERR_NOERROR )
|
||||
{
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// _glfwCalcJoystickPos() - Calculate joystick position
|
||||
//========================================================================
|
||||
|
||||
static float _glfwCalcJoystickPos( DWORD pos, DWORD min, DWORD max )
|
||||
{
|
||||
float fpos = (float) pos;
|
||||
float fmin = (float) min;
|
||||
float fmax = (float) max;
|
||||
return (2.0f*(fpos - fmin) / (fmax - fmin)) - 1.0f;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//************************************************************************
|
||||
//**** Platform implementation functions ****
|
||||
//************************************************************************
|
||||
|
||||
//========================================================================
|
||||
// _glfwPlatformGetJoystickParam() - Determine joystick capabilities
|
||||
//========================================================================
|
||||
|
||||
int _glfwPlatformGetJoystickParam( int joy, int param )
|
||||
{
|
||||
JOYCAPS jc;
|
||||
|
||||
// return 0;
|
||||
|
||||
// Is joystick present?
|
||||
if( !_glfwJoystickPresent( joy ) )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// We got this far, the joystick is present
|
||||
if( param == GLFW_PRESENT )
|
||||
{
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
// Get joystick capabilities
|
||||
_glfw_joyGetDevCaps( joy - GLFW_JOYSTICK_1, &jc, sizeof(JOYCAPS) );
|
||||
|
||||
switch( param )
|
||||
{
|
||||
case GLFW_AXES:
|
||||
// Return number of joystick axes
|
||||
return jc.wNumAxes;
|
||||
|
||||
case GLFW_BUTTONS:
|
||||
// Return number of joystick axes
|
||||
return jc.wNumButtons;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// _glfwPlatformGetJoystickPos() - Get joystick axis positions
|
||||
//========================================================================
|
||||
|
||||
int _glfwPlatformGetJoystickPos( int joy, float *pos, int numaxes )
|
||||
{
|
||||
JOYCAPS jc;
|
||||
JOYINFOEX ji;
|
||||
int axis;
|
||||
|
||||
// return 0;
|
||||
|
||||
// Is joystick present?
|
||||
if( !_glfwJoystickPresent( joy ) )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Get joystick capabilities
|
||||
_glfw_joyGetDevCaps( joy - GLFW_JOYSTICK_1, &jc, sizeof(JOYCAPS) );
|
||||
|
||||
// Get joystick state
|
||||
ji.dwSize = sizeof( JOYINFOEX );
|
||||
ji.dwFlags = JOY_RETURNX | JOY_RETURNY | JOY_RETURNZ |
|
||||
JOY_RETURNR | JOY_RETURNU | JOY_RETURNV;
|
||||
_glfw_joyGetPosEx( joy - GLFW_JOYSTICK_1, &ji );
|
||||
|
||||
// Get position values for all axes
|
||||
axis = 0;
|
||||
if( axis < numaxes )
|
||||
{
|
||||
pos[ axis++ ] = _glfwCalcJoystickPos( ji.dwXpos, jc.wXmin,
|
||||
jc.wXmax );
|
||||
}
|
||||
if( axis < numaxes )
|
||||
{
|
||||
pos[ axis++ ] = -_glfwCalcJoystickPos( ji.dwYpos, jc.wYmin,
|
||||
jc.wYmax );
|
||||
}
|
||||
if( axis < numaxes && jc.wCaps & JOYCAPS_HASZ )
|
||||
{
|
||||
pos[ axis++ ] = _glfwCalcJoystickPos( ji.dwZpos, jc.wZmin,
|
||||
jc.wZmax );
|
||||
}
|
||||
if( axis < numaxes && jc.wCaps & JOYCAPS_HASR )
|
||||
{
|
||||
pos[ axis++ ] = _glfwCalcJoystickPos( ji.dwRpos, jc.wRmin,
|
||||
jc.wRmax );
|
||||
}
|
||||
if( axis < numaxes && jc.wCaps & JOYCAPS_HASU )
|
||||
{
|
||||
pos[ axis++ ] = _glfwCalcJoystickPos( ji.dwUpos, jc.wUmin,
|
||||
jc.wUmax );
|
||||
}
|
||||
if( axis < numaxes && jc.wCaps & JOYCAPS_HASV )
|
||||
{
|
||||
pos[ axis++ ] = -_glfwCalcJoystickPos( ji.dwVpos, jc.wVmin,
|
||||
jc.wVmax );
|
||||
}
|
||||
|
||||
// Return number of returned axes
|
||||
return axis;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// _glfwPlatformGetJoystickButtons() - Get joystick button states
|
||||
//========================================================================
|
||||
|
||||
int _glfwPlatformGetJoystickButtons( int joy, unsigned char *buttons,
|
||||
int numbuttons )
|
||||
{
|
||||
JOYCAPS jc;
|
||||
JOYINFOEX ji;
|
||||
int button;
|
||||
|
||||
// return 0;
|
||||
|
||||
// Is joystick present?
|
||||
if( !_glfwJoystickPresent( joy ) )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Get joystick capabilities
|
||||
_glfw_joyGetDevCaps( joy - GLFW_JOYSTICK_1, &jc, sizeof(JOYCAPS) );
|
||||
|
||||
// Get joystick state
|
||||
ji.dwSize = sizeof( JOYINFOEX );
|
||||
ji.dwFlags = JOY_RETURNBUTTONS;
|
||||
_glfw_joyGetPosEx( joy - GLFW_JOYSTICK_1, &ji );
|
||||
|
||||
// Get states of all requested buttons
|
||||
button = 0;
|
||||
while( button < numbuttons && button < (int) jc.wNumButtons )
|
||||
{
|
||||
buttons[ button ] = (unsigned char)
|
||||
(ji.dwButtons & (1UL << button) ? GLFW_PRESS : GLFW_RELEASE);
|
||||
button ++;
|
||||
}
|
||||
|
||||
return button;
|
||||
}
|
||||
|
511
libs/glfw/lib/win32/win32_thread.c
Normal file
511
libs/glfw/lib/win32/win32_thread.c
Normal file
@ -0,0 +1,511 @@
|
||||
//========================================================================
|
||||
// GLFW - An OpenGL framework
|
||||
// File: win32_thread.c
|
||||
// Platform: Windows
|
||||
// API version: 2.6
|
||||
// WWW: http://glfw.sourceforge.net
|
||||
//------------------------------------------------------------------------
|
||||
// Copyright (c) 2002-2006 Camilla Berglund
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would
|
||||
// be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not
|
||||
// be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
//************************************************************************
|
||||
// This is an implementation of POSIX "compatible" condition variables for
|
||||
// Win32, as described by Douglas C. Schmidt and Irfan Pyarali:
|
||||
// http://www.cs.wustl.edu/~schmidt/win32-cv-1.html
|
||||
//************************************************************************
|
||||
|
||||
enum {
|
||||
_GLFW_COND_SIGNAL = 0,
|
||||
_GLFW_COND_BROADCAST = 1
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
// Signal and broadcast event HANDLEs
|
||||
HANDLE events[ 2 ];
|
||||
|
||||
// Count of the number of waiters
|
||||
unsigned int waiters_count;
|
||||
|
||||
// Serialize access to <waiters_count>
|
||||
CRITICAL_SECTION waiters_count_lock;
|
||||
} _GLFWcond;
|
||||
|
||||
|
||||
|
||||
//************************************************************************
|
||||
//**** GLFW internal functions ****
|
||||
//************************************************************************
|
||||
|
||||
//========================================================================
|
||||
// _glfwNewThread() - This is simply a "wrapper" for calling the user
|
||||
// thread function.
|
||||
//========================================================================
|
||||
|
||||
DWORD WINAPI _glfwNewThread( LPVOID lpParam )
|
||||
{
|
||||
GLFWthreadfun threadfun;
|
||||
_GLFWthread *t;
|
||||
|
||||
// Get pointer to thread information for current thread
|
||||
t = _glfwGetThreadPointer( _glfwPlatformGetThreadID() );
|
||||
if( t == NULL )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Get user thread function pointer
|
||||
threadfun = t->Function;
|
||||
|
||||
// Call the user thread function
|
||||
threadfun( (void *) lpParam );
|
||||
|
||||
// Remove thread from thread list
|
||||
ENTER_THREAD_CRITICAL_SECTION
|
||||
_glfwRemoveThread( t );
|
||||
LEAVE_THREAD_CRITICAL_SECTION
|
||||
|
||||
// When the thread function returns, the thread will die...
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//************************************************************************
|
||||
//**** GLFW user functions ****
|
||||
//************************************************************************
|
||||
|
||||
//========================================================================
|
||||
// _glfwPlatformCreateThread() - Create a new thread
|
||||
//========================================================================
|
||||
|
||||
GLFWthread _glfwPlatformCreateThread( GLFWthreadfun fun, void *arg )
|
||||
{
|
||||
GLFWthread ID;
|
||||
_GLFWthread *t, *t_tmp;
|
||||
HANDLE hThread;
|
||||
DWORD dwThreadId;
|
||||
|
||||
// Enter critical section
|
||||
ENTER_THREAD_CRITICAL_SECTION
|
||||
|
||||
// Create a new thread information memory area
|
||||
t = (_GLFWthread *) malloc( sizeof(_GLFWthread) );
|
||||
if( t == NULL )
|
||||
{
|
||||
// Leave critical section
|
||||
LEAVE_THREAD_CRITICAL_SECTION
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Get a new unique thread id
|
||||
ID = _glfwThrd.NextID ++;
|
||||
|
||||
// Store thread information in the thread list
|
||||
t->Function = fun;
|
||||
t->ID = ID;
|
||||
|
||||
// Create thread
|
||||
hThread = CreateThread(
|
||||
NULL, // Default security attributes
|
||||
0, // Default stack size (1 MB)
|
||||
_glfwNewThread, // Thread function (a wrapper function)
|
||||
(LPVOID)arg, // Argument to thread is the user argument
|
||||
0, // Default creation flags
|
||||
&dwThreadId // Returned thread identifier
|
||||
);
|
||||
|
||||
// Did the thread creation fail?
|
||||
if( hThread == NULL )
|
||||
{
|
||||
free( (void *) t );
|
||||
LEAVE_THREAD_CRITICAL_SECTION
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Store more thread information in the thread list
|
||||
t->Handle = hThread;
|
||||
t->WinID = dwThreadId;
|
||||
|
||||
// Append thread to thread list
|
||||
t_tmp = &_glfwThrd.First;
|
||||
while( t_tmp->Next != NULL )
|
||||
{
|
||||
t_tmp = t_tmp->Next;
|
||||
}
|
||||
t_tmp->Next = t;
|
||||
t->Previous = t_tmp;
|
||||
t->Next = NULL;
|
||||
|
||||
// Leave critical section
|
||||
LEAVE_THREAD_CRITICAL_SECTION
|
||||
|
||||
// Return the GLFW thread ID
|
||||
return ID;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// _glfwPlatformDestroyThread() - Kill a thread. NOTE: THIS IS A VERY
|
||||
// DANGEROUS OPERATION, AND SHOULD NOT BE USED EXCEPT IN EXTREME
|
||||
// SITUATIONS!
|
||||
//========================================================================
|
||||
|
||||
void _glfwPlatformDestroyThread( GLFWthread ID )
|
||||
{
|
||||
_GLFWthread *t;
|
||||
|
||||
// Enter critical section
|
||||
ENTER_THREAD_CRITICAL_SECTION
|
||||
|
||||
// Get thread information pointer
|
||||
t = _glfwGetThreadPointer( ID );
|
||||
if( t == NULL )
|
||||
{
|
||||
LEAVE_THREAD_CRITICAL_SECTION
|
||||
return;
|
||||
}
|
||||
|
||||
// Simply murder the process, no mercy!
|
||||
if( TerminateThread( t->Handle, 0 ) )
|
||||
{
|
||||
// Close thread handle
|
||||
CloseHandle( t->Handle );
|
||||
|
||||
// Remove thread from thread list
|
||||
_glfwRemoveThread( t );
|
||||
}
|
||||
|
||||
// Leave critical section
|
||||
LEAVE_THREAD_CRITICAL_SECTION
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// _glfwPlatformWaitThread() - Wait for a thread to die
|
||||
//========================================================================
|
||||
|
||||
int _glfwPlatformWaitThread( GLFWthread ID, int waitmode )
|
||||
{
|
||||
DWORD result;
|
||||
HANDLE hThread;
|
||||
_GLFWthread *t;
|
||||
|
||||
// Enter critical section
|
||||
ENTER_THREAD_CRITICAL_SECTION
|
||||
|
||||
// Get thread information pointer
|
||||
t = _glfwGetThreadPointer( ID );
|
||||
|
||||
// Is the thread already dead?
|
||||
if( t == NULL )
|
||||
{
|
||||
LEAVE_THREAD_CRITICAL_SECTION
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
// Get thread handle
|
||||
hThread = t->Handle;
|
||||
|
||||
// Leave critical section
|
||||
LEAVE_THREAD_CRITICAL_SECTION
|
||||
|
||||
// Wait for thread to die
|
||||
if( waitmode == GLFW_WAIT )
|
||||
{
|
||||
result = WaitForSingleObject( hThread, INFINITE );
|
||||
}
|
||||
else if( waitmode == GLFW_NOWAIT )
|
||||
{
|
||||
result = WaitForSingleObject( hThread, 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
// Did we have a time-out?
|
||||
if( result == WAIT_TIMEOUT )
|
||||
{
|
||||
return GL_FALSE;
|
||||
}
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// _glfwPlatformGetThreadID() - Return the thread ID for the current
|
||||
// thread
|
||||
//========================================================================
|
||||
|
||||
GLFWthread _glfwPlatformGetThreadID( void )
|
||||
{
|
||||
_GLFWthread *t;
|
||||
GLFWthread ID = -1;
|
||||
DWORD WinID;
|
||||
|
||||
// Get Windows thread ID
|
||||
WinID = GetCurrentThreadId();
|
||||
|
||||
// Enter critical section (to avoid an inconsistent thread list)
|
||||
ENTER_THREAD_CRITICAL_SECTION
|
||||
|
||||
// Loop through entire list of threads to find the matching Windows
|
||||
// thread ID
|
||||
for( t = &_glfwThrd.First; t != NULL; t = t->Next )
|
||||
{
|
||||
if( t->WinID == WinID )
|
||||
{
|
||||
ID = t->ID;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Leave critical section
|
||||
LEAVE_THREAD_CRITICAL_SECTION
|
||||
|
||||
// Return the found GLFW thread identifier
|
||||
return ID;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// _glfwPlatformCreateMutex() - Create a mutual exclusion object
|
||||
//========================================================================
|
||||
|
||||
GLFWmutex _glfwPlatformCreateMutex( void )
|
||||
{
|
||||
CRITICAL_SECTION *mutex;
|
||||
|
||||
// Allocate memory for mutex
|
||||
mutex = (CRITICAL_SECTION *) malloc( sizeof(CRITICAL_SECTION) );
|
||||
if( !mutex )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Initialize mutex
|
||||
InitializeCriticalSection( mutex );
|
||||
|
||||
// Cast to GLFWmutex and return
|
||||
return (GLFWmutex) mutex;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// glfwDestroyMutex() - Destroy a mutual exclusion object
|
||||
//========================================================================
|
||||
|
||||
void _glfwPlatformDestroyMutex( GLFWmutex mutex )
|
||||
{
|
||||
// Destroy mutex
|
||||
DeleteCriticalSection( (CRITICAL_SECTION *) mutex );
|
||||
free( mutex );
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// _glfwPlatformLockMutex() - Request access to a mutex
|
||||
//========================================================================
|
||||
|
||||
void _glfwPlatformLockMutex( GLFWmutex mutex )
|
||||
{
|
||||
// Wait for mutex to be released
|
||||
EnterCriticalSection( (CRITICAL_SECTION *) mutex );
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// _glfwPlatformUnlockMutex() - Release a mutex
|
||||
//========================================================================
|
||||
|
||||
void _glfwPlatformUnlockMutex( GLFWmutex mutex )
|
||||
{
|
||||
// Release mutex
|
||||
LeaveCriticalSection( (CRITICAL_SECTION *) mutex );
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// _glfwPlatformCreateCond() - Create a new condition variable object
|
||||
//========================================================================
|
||||
|
||||
GLFWcond _glfwPlatformCreateCond( void )
|
||||
{
|
||||
_GLFWcond *cond;
|
||||
|
||||
// Allocate memory for condition variable
|
||||
cond = (_GLFWcond *) malloc( sizeof(_GLFWcond) );
|
||||
if( !cond )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Initialize condition variable
|
||||
cond->waiters_count = 0;
|
||||
cond->events[ _GLFW_COND_SIGNAL ] = CreateEvent( NULL, FALSE,
|
||||
FALSE, NULL );
|
||||
cond->events[ _GLFW_COND_BROADCAST ] = CreateEvent( NULL, TRUE,
|
||||
FALSE, NULL );
|
||||
InitializeCriticalSection( &cond->waiters_count_lock );
|
||||
|
||||
// Cast to GLFWcond and return
|
||||
return (GLFWcond) cond;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// _glfwPlatformDestroyCond() - Destroy a condition variable object
|
||||
//========================================================================
|
||||
|
||||
void _glfwPlatformDestroyCond( GLFWcond cond )
|
||||
{
|
||||
// Close the condition variable handles
|
||||
CloseHandle( ((_GLFWcond *)cond)->events[ _GLFW_COND_SIGNAL ] );
|
||||
CloseHandle( ((_GLFWcond *)cond)->events[ _GLFW_COND_BROADCAST ] );
|
||||
|
||||
// Delete critical section
|
||||
DeleteCriticalSection( &((_GLFWcond *)cond)->waiters_count_lock );
|
||||
|
||||
// Free memory for condition variable
|
||||
free( (void *) cond );
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// _glfwPlatformWaitCond() - Wait for a condition to be raised
|
||||
//========================================================================
|
||||
|
||||
void _glfwPlatformWaitCond( GLFWcond cond, GLFWmutex mutex,
|
||||
double timeout )
|
||||
{
|
||||
_GLFWcond *cv = (_GLFWcond *) cond;
|
||||
int result, last_waiter;
|
||||
DWORD timeout_ms;
|
||||
|
||||
// Avoid race conditions
|
||||
EnterCriticalSection( &cv->waiters_count_lock );
|
||||
cv->waiters_count ++;
|
||||
LeaveCriticalSection( &cv->waiters_count_lock );
|
||||
|
||||
// It's ok to release the mutex here since Win32 manual-reset events
|
||||
// maintain state when used with SetEvent()
|
||||
LeaveCriticalSection( (CRITICAL_SECTION *) mutex );
|
||||
|
||||
// Translate timeout into milliseconds
|
||||
if( timeout >= GLFW_INFINITY )
|
||||
{
|
||||
timeout_ms = INFINITE;
|
||||
}
|
||||
else
|
||||
{
|
||||
timeout_ms = (DWORD) (1000.0 * timeout + 0.5);
|
||||
if( timeout_ms <= 0 )
|
||||
{
|
||||
timeout_ms = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Wait for either event to become signaled due to glfwSignalCond or
|
||||
// glfwBroadcastCond being called
|
||||
result = WaitForMultipleObjects( 2, cv->events, FALSE, timeout_ms );
|
||||
|
||||
// Check if we are the last waiter
|
||||
EnterCriticalSection( &cv->waiters_count_lock );
|
||||
cv->waiters_count --;
|
||||
last_waiter = (result == WAIT_OBJECT_0 + _GLFW_COND_BROADCAST) &&
|
||||
(cv->waiters_count == 0);
|
||||
LeaveCriticalSection( &cv->waiters_count_lock );
|
||||
|
||||
// Some thread called glfwBroadcastCond
|
||||
if( last_waiter )
|
||||
{
|
||||
// We're the last waiter to be notified or to stop waiting, so
|
||||
// reset the manual event
|
||||
ResetEvent( cv->events[ _GLFW_COND_BROADCAST ] );
|
||||
}
|
||||
|
||||
// Reacquire the mutex
|
||||
EnterCriticalSection( (CRITICAL_SECTION *) mutex );
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// _glfwPlatformSignalCond() - Signal a condition to one waiting thread
|
||||
//========================================================================
|
||||
|
||||
void _glfwPlatformSignalCond( GLFWcond cond )
|
||||
{
|
||||
_GLFWcond *cv = (_GLFWcond *) cond;
|
||||
int have_waiters;
|
||||
|
||||
// Avoid race conditions
|
||||
EnterCriticalSection( &cv->waiters_count_lock );
|
||||
have_waiters = cv->waiters_count > 0;
|
||||
LeaveCriticalSection( &cv->waiters_count_lock );
|
||||
|
||||
if( have_waiters )
|
||||
{
|
||||
SetEvent( cv->events[ _GLFW_COND_SIGNAL ] );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// _glfwPlatformBroadcastCond() - Broadcast a condition to all waiting
|
||||
// threads
|
||||
//========================================================================
|
||||
|
||||
void _glfwPlatformBroadcastCond( GLFWcond cond )
|
||||
{
|
||||
_GLFWcond *cv = (_GLFWcond *) cond;
|
||||
int have_waiters;
|
||||
|
||||
// Avoid race conditions
|
||||
EnterCriticalSection( &cv->waiters_count_lock );
|
||||
have_waiters = cv->waiters_count > 0;
|
||||
LeaveCriticalSection( &cv->waiters_count_lock );
|
||||
|
||||
if( have_waiters )
|
||||
{
|
||||
SetEvent( cv->events[ _GLFW_COND_BROADCAST ] );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// _glfwPlatformGetNumberOfProcessors() - Return the number of processors
|
||||
// in the system.
|
||||
//========================================================================
|
||||
|
||||
int _glfwPlatformGetNumberOfProcessors( void )
|
||||
{
|
||||
SYSTEM_INFO si;
|
||||
|
||||
// Get hardware system information
|
||||
GetSystemInfo( &si );
|
||||
|
||||
return (int) si.dwNumberOfProcessors;
|
||||
}
|
146
libs/glfw/lib/win32/win32_time.c
Normal file
146
libs/glfw/lib/win32/win32_time.c
Normal file
@ -0,0 +1,146 @@
|
||||
//========================================================================
|
||||
// GLFW - An OpenGL framework
|
||||
// File: win32_time.c
|
||||
// Platform: Windows
|
||||
// API version: 2.6
|
||||
// WWW: http://glfw.sourceforge.net
|
||||
//------------------------------------------------------------------------
|
||||
// Copyright (c) 2002-2006 Camilla Berglund
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would
|
||||
// be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not
|
||||
// be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
//************************************************************************
|
||||
//**** GLFW internal functions ****
|
||||
//************************************************************************
|
||||
|
||||
//========================================================================
|
||||
// _glfwInitTimer() - Initialise timer
|
||||
//========================================================================
|
||||
|
||||
void _glfwInitTimer( void )
|
||||
{
|
||||
__int64 freq;
|
||||
|
||||
// Check if we have a performance counter
|
||||
if( QueryPerformanceFrequency( (LARGE_INTEGER *)&freq ) )
|
||||
{
|
||||
// Performance counter is available => use it!
|
||||
_glfwLibrary.Timer.HasPerformanceCounter = GL_TRUE;
|
||||
|
||||
// Counter resolution is 1 / counter frequency
|
||||
_glfwLibrary.Timer.Resolution = 1.0 / (double)freq;
|
||||
|
||||
// Set start time for timer
|
||||
QueryPerformanceCounter( (LARGE_INTEGER *)&_glfwLibrary.Timer.t0_64 );
|
||||
}
|
||||
else
|
||||
{
|
||||
// No performace counter available => use the tick counter
|
||||
_glfwLibrary.Timer.HasPerformanceCounter = GL_FALSE;
|
||||
|
||||
// Counter resolution is 1 ms
|
||||
_glfwLibrary.Timer.Resolution = 0.001;
|
||||
|
||||
// Set start time for timer
|
||||
_glfwLibrary.Timer.t0_32 = _glfw_timeGetTime();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//************************************************************************
|
||||
//**** Platform implementation functions ****
|
||||
//************************************************************************
|
||||
|
||||
//========================================================================
|
||||
// Return timer value in seconds
|
||||
//========================================================================
|
||||
|
||||
double _glfwPlatformGetTime( void )
|
||||
{
|
||||
double t;
|
||||
__int64 t_64;
|
||||
|
||||
if( _glfwLibrary.Timer.HasPerformanceCounter )
|
||||
{
|
||||
QueryPerformanceCounter( (LARGE_INTEGER *)&t_64 );
|
||||
t = (double)(t_64 - _glfwLibrary.Timer.t0_64);
|
||||
}
|
||||
else
|
||||
{
|
||||
t = (double)(_glfw_timeGetTime() - _glfwLibrary.Timer.t0_32);
|
||||
}
|
||||
|
||||
// Calculate the current time in seconds
|
||||
return t * _glfwLibrary.Timer.Resolution;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Set timer value in seconds
|
||||
//========================================================================
|
||||
|
||||
void _glfwPlatformSetTime( double t )
|
||||
{
|
||||
__int64 t_64;
|
||||
|
||||
if( _glfwLibrary.Timer.HasPerformanceCounter )
|
||||
{
|
||||
QueryPerformanceCounter( (LARGE_INTEGER *)&t_64 );
|
||||
_glfwLibrary.Timer.t0_64 = t_64 - (__int64)(t/_glfwLibrary.Timer.Resolution);
|
||||
}
|
||||
else
|
||||
{
|
||||
_glfwLibrary.Timer.t0_32 = _glfw_timeGetTime() - (int)(t*1000.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Put a thread to sleep for a specified amount of time
|
||||
//========================================================================
|
||||
|
||||
void _glfwPlatformSleep( double time )
|
||||
{
|
||||
DWORD t;
|
||||
|
||||
if( time == 0.0 )
|
||||
{
|
||||
t = 0;
|
||||
}
|
||||
else if( time < 0.001 )
|
||||
{
|
||||
t = 1;
|
||||
}
|
||||
else if( time > 2147483647.0 )
|
||||
{
|
||||
t = 2147483647;
|
||||
}
|
||||
else
|
||||
{
|
||||
t = (DWORD)(time*1000.0 + 0.5);
|
||||
}
|
||||
Sleep( t );
|
||||
}
|
||||
|
1714
libs/glfw/lib/win32/win32_window.c
Normal file
1714
libs/glfw/lib/win32/win32_window.c
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user