summaryrefslogtreecommitdiff
path: root/platform/windows
diff options
context:
space:
mode:
Diffstat (limited to 'platform/windows')
-rw-r--r--platform/windows/context_gl_win.cpp17
-rw-r--r--platform/windows/context_gl_win.h8
-rw-r--r--platform/windows/detect.py2
-rw-r--r--platform/windows/os_windows.cpp107
-rw-r--r--platform/windows/os_windows.h3
5 files changed, 119 insertions, 18 deletions
diff --git a/platform/windows/context_gl_win.cpp b/platform/windows/context_gl_win.cpp
index ab66b81421..fd9e895370 100644
--- a/platform/windows/context_gl_win.cpp
+++ b/platform/windows/context_gl_win.cpp
@@ -96,6 +96,20 @@ static GLWrapperFuncPtr wrapper_get_proc_address(const char* p_function) {
}
*/
+void ContextGL_Win::set_use_vsync(bool p_use) {
+
+ if (wglSwapIntervalEXT) {
+ wglSwapIntervalEXT(p_use?1:0);
+ }
+ use_vsync=p_use;
+
+}
+
+bool ContextGL_Win::is_using_vsync() const {
+
+ return use_vsync;
+}
+
Error ContextGL_Win::initialize() {
@@ -184,7 +198,7 @@ Error ContextGL_Win::initialize() {
printf("Activated GL 3.1 context");
}
-
+ wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC) wglGetProcAddress ("wglSwapIntervalEXT");
// glWrapperInit(wrapper_get_proc_address);
return OK;
@@ -194,6 +208,7 @@ ContextGL_Win::ContextGL_Win(HWND hwnd,bool p_opengl_3_context) {
opengl_3_context=p_opengl_3_context;
hWnd=hwnd;
+ use_vsync=false;
}
ContextGL_Win::~ContextGL_Win() {
diff --git a/platform/windows/context_gl_win.h b/platform/windows/context_gl_win.h
index 055e0b2f51..e1ab6fb26a 100644
--- a/platform/windows/context_gl_win.h
+++ b/platform/windows/context_gl_win.h
@@ -49,6 +49,8 @@
#include <windows.h>
+typedef bool (APIENTRY *PFNWGLSWAPINTERVALEXTPROC) (int interval);
+
class ContextGL_Win : public ContextGL {
HDC hDC;
@@ -56,6 +58,10 @@ class ContextGL_Win : public ContextGL {
unsigned int pixel_format;
HWND hWnd;
bool opengl_3_context;
+ bool use_vsync;
+
+
+ PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT;
public:
@@ -69,6 +75,8 @@ public:
virtual Error initialize();
+ virtual void set_use_vsync(bool p_use);
+ virtual bool is_using_vsync() const;
ContextGL_Win(HWND hwnd,bool p_opengl_3_context);
~ContextGL_Win();
diff --git a/platform/windows/detect.py b/platform/windows/detect.py
index 4edae9cceb..97d2461e58 100644
--- a/platform/windows/detect.py
+++ b/platform/windows/detect.py
@@ -243,7 +243,7 @@ def configure(env):
env.Append(CCFLAGS=['/DGLES2_ENABLED'])
env.Append(CCFLAGS=['/DGLEW_ENABLED'])
- LIBS=['winmm','opengl32','dsound','kernel32','ole32','oleaut32','user32','gdi32', 'IPHLPAPI','Shcore','Shlwapi', 'wsock32', 'shell32','advapi32','dinput8','dxguid']
+ LIBS=['winmm','opengl32','dsound','kernel32','ole32','oleaut32','user32','gdi32', 'IPHLPAPI','Shlwapi', 'wsock32', 'shell32','advapi32','dinput8','dxguid']
env.Append(LINKFLAGS=[p+env["LIBSUFFIX"] for p in LIBS])
env.Append(LIBPATH=[os.getenv("WindowsSdkDir")+"/Lib"])
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp
index 8bb5de5d5d..5e3dc438d0 100644
--- a/platform/windows/os_windows.cpp
+++ b/platform/windows/os_windows.cpp
@@ -57,13 +57,6 @@
#include <regstr.h>
#include <process.h>
-#if (_MSC_VER >= 1700)
-#define HIDPI_SUPPORT
-#endif
-
-#ifdef HIDPI_SUPPORT
-#include <ShellScalingAPI.h>
-#endif
static const WORD MAX_CONSOLE_LINES = 1500;
extern "C" {
@@ -781,6 +774,8 @@ LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) {
}
+
+
void OS_Windows::process_key_events() {
for(int i=0;i<key_event_pos;i++) {
@@ -800,7 +795,7 @@ void OS_Windows::process_key_events() {
k.mod=ke.mod_state;
k.pressed=true;
k.scancode=KeyMappingWindows::get_keysym(ke.wParam);
- k.unicode=ke.wParam;
+ k.unicode=ke.wParam;
if (k.unicode && gr_mem) {
k.mod.alt=false;
k.mod.control=false;
@@ -852,6 +847,75 @@ void OS_Windows::process_key_events() {
key_event_pos=0;
}
+enum _MonitorDpiType
+{
+ MDT_Effective_DPI = 0,
+ MDT_Angular_DPI = 1,
+ MDT_Raw_DPI = 2,
+ MDT_Default = MDT_Effective_DPI
+};
+
+
+static int QueryDpiForMonitor(HMONITOR hmon, _MonitorDpiType dpiType= MDT_Default)
+{
+
+
+ int dpiX = 96, dpiY = 96;
+
+ static HMODULE Shcore = NULL;
+ typedef HRESULT (WINAPI* GetDPIForMonitor_t)(HMONITOR hmonitor, _MonitorDpiType dpiType, UINT *dpiX, UINT *dpiY);
+ static GetDPIForMonitor_t getDPIForMonitor = NULL;
+
+ if (Shcore == NULL)
+ {
+ Shcore = LoadLibraryW(L"Shcore.dll");
+ getDPIForMonitor = Shcore ? (GetDPIForMonitor_t)GetProcAddress(Shcore, "GetDpiForMonitor") : NULL;
+
+ if ((Shcore == NULL) || (getDPIForMonitor == NULL))
+ {
+ if (Shcore)
+ FreeLibrary(Shcore);
+ Shcore = (HMODULE)INVALID_HANDLE_VALUE;
+ }
+ }
+
+ UINT x = 0, y = 0;
+ HRESULT hr = E_FAIL;
+ bool bSet = false;
+ if (hmon && (Shcore != (HMODULE)INVALID_HANDLE_VALUE))
+ {
+ hr = getDPIForMonitor(hmon, dpiType/*MDT_Effective_DPI*/, &x, &y);
+ if (SUCCEEDED(hr) && (x > 0) && (y > 0))
+ {
+
+ dpiX = (int)x;
+ dpiY = (int)y;
+ }
+ }
+ else
+ {
+ static int overallX = 0, overallY = 0;
+ if (overallX <= 0 || overallY <= 0)
+ {
+ HDC hdc = GetDC(NULL);
+ if (hdc)
+ {
+ overallX = GetDeviceCaps(hdc, LOGPIXELSX);
+ overallY = GetDeviceCaps(hdc, LOGPIXELSY);
+ ReleaseDC(NULL, hdc);
+ }
+ }
+ if (overallX > 0 && overallY > 0)
+ {
+ dpiX = overallX; dpiY = overallY;
+ }
+ }
+
+
+ return (dpiX+dpiY)/2;
+}
+
+
BOOL CALLBACK OS_Windows::MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) {
OS_Windows *self=(OS_Windows*)OS::get_singleton();
MonitorInfo minfo;
@@ -861,13 +925,9 @@ BOOL CALLBACK OS_Windows::MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPR
minfo.rect.pos.y=lprcMonitor->top;
minfo.rect.size.x=lprcMonitor->right - lprcMonitor->left;
minfo.rect.size.y=lprcMonitor->bottom - lprcMonitor->top;
-#ifdef HIDPI_SUPPORT
- UINT dpix,dpiy;
- GetDpiForMonitor(hMonitor,MDT_EFFECTIVE_DPI,&dpix,&dpiy);
- minfo.dpi=(dpix + dpiy)/2;
-#else
- minfo.dpi=72;
-#endif
+
+ minfo.dpi = QueryDpiForMonitor(hMonitor);
+
self->monitor_info.push_back(minfo);
return TRUE;
@@ -2183,7 +2243,7 @@ String OS_Windows::get_system_dir(SystemDir p_dir) const {
}
String OS_Windows::get_data_dir() const {
- String an = Globals::get_singleton()->get("application/name");
+ String an = get_safe_application_name();
if (an!="") {
if (has_environment("APPDATA")) {
@@ -2209,6 +2269,21 @@ String OS_Windows::get_joy_guid(int p_device) const {
return input->get_joy_guid_remapped(p_device);
}
+void OS_Windows::set_use_vsync(bool p_enable) {
+
+ if (gl_context)
+ gl_context->set_use_vsync(p_enable);
+}
+
+bool OS_Windows::is_vsnc_enabled() const{
+
+ if (gl_context)
+ return gl_context->is_using_vsync();
+
+ return true;
+}
+
+
OS_Windows::OS_Windows(HINSTANCE _hInstance) {
key_event_pos=0;
diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h
index 6dd5b78bfd..509d76abbf 100644
--- a/platform/windows/os_windows.h
+++ b/platform/windows/os_windows.h
@@ -283,6 +283,9 @@ public:
virtual bool is_joy_known(int p_device);
virtual String get_joy_guid(int p_device) const;
+ virtual void set_use_vsync(bool p_enable);
+ virtual bool is_vsnc_enabled() const;
+
OS_Windows(HINSTANCE _hInstance);
~OS_Windows();