10 #include "../stdafx.h"
11 #include "../openttd.h"
12 #include "../gfx_func.h"
13 #include "../os/windows/win32.h"
15 #include "../blitter/factory.hpp"
16 #include "../core/geometry_func.hpp"
17 #include "../core/math_func.hpp"
18 #include "../core/random_func.hpp"
19 #include "../texteff.hpp"
20 #include "../thread.h"
21 #include "../progress.h"
22 #include "../window_gui.h"
23 #include "../window_func.h"
24 #include "../framerate_type.h"
28 #include <versionhelpers.h>
30 #include "../safeguards.h"
33 #ifndef MAPVK_VK_TO_CHAR
34 #define MAPVK_VK_TO_CHAR (2)
38 #define PM_QS_INPUT 0x20000
41 bool _window_maximize;
47 bool VideoDriver_Win32Base::ClaimMousePointer()
49 MyShowCursor(
false,
true);
59 #define AS(x, z) {x, 0, z}
60 #define AM(x, y, z, w) {x, y - x, z}
64 AM(VK_PRIOR, VK_DOWN, WKC_PAGEUP, WKC_DOWN),
66 AM(
'A',
'Z',
'A',
'Z'),
67 AM(
'0',
'9',
'0',
'9'),
69 AS(VK_ESCAPE, WKC_ESC),
70 AS(VK_PAUSE, WKC_PAUSE),
71 AS(VK_BACK, WKC_BACKSPACE),
72 AM(VK_INSERT, VK_DELETE, WKC_INSERT, WKC_DELETE),
74 AS(VK_SPACE, WKC_SPACE),
75 AS(VK_RETURN, WKC_RETURN),
79 AM(VK_F1, VK_F12, WKC_F1, WKC_F12),
82 AM(VK_NUMPAD0, VK_NUMPAD9,
'0',
'9'),
83 AS(VK_DIVIDE, WKC_NUM_DIV),
84 AS(VK_MULTIPLY, WKC_NUM_MUL),
85 AS(VK_SUBTRACT, WKC_NUM_MINUS),
86 AS(VK_ADD, WKC_NUM_PLUS),
87 AS(VK_DECIMAL, WKC_NUM_DECIMAL),
103 static uint MapWindowsKey(uint sym)
108 for (map = _vk_mapping; map !=
endof(_vk_mapping); ++map) {
109 if ((uint)(sym - map->vk_from) <= map->vk_count) {
110 key = sym - map->vk_from + map->map_to;
115 if (GetAsyncKeyState(VK_SHIFT) < 0) key |= WKC_SHIFT;
116 if (GetAsyncKeyState(VK_CONTROL) < 0) key |= WKC_CTRL;
117 if (GetAsyncKeyState(VK_MENU) < 0) key |= WKC_ALT;
138 _fullscreen = full_screen;
160 if (settings.dmBitsPerPel == 8 && ChangeDisplaySettings(&
settings, CDS_FULLSCREEN | CDS_TEST) != DISP_CHANGE_SUCCESSFUL) {
165 if (ChangeDisplaySettings(&
settings, CDS_FULLSCREEN | CDS_TEST) != DISP_CHANGE_SUCCESSFUL) {
167 GetWindowRect(GetDesktopWindow(), &r);
170 if ((
int)
settings.dmPelsWidth != r.right - r.left || (
int)
settings.dmPelsHeight != r.bottom - r.top) {
175 if (ChangeDisplaySettings(&
settings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) {
181 ChangeDisplaySettings(
nullptr, 0);
183 this->
width = _bck_resolution.width;
184 this->
height = _bck_resolution.height;
189 DWORD style, showstyle;
192 showstyle = SW_SHOWNORMAL;
198 style = WS_OVERLAPPEDWINDOW;
200 if (_window_maximize) showstyle = SW_SHOWMAXIMIZED;
204 AdjustWindowRect(&r, style, FALSE);
205 w = r.right - r.left;
206 h = r.bottom - r.top;
209 if (!_window_maximize && resize) SetWindowPos(this->
main_wnd, 0, 0, 0, w, h, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOMOVE);
211 int x = (GetSystemMetrics(SM_CXSCREEN) - w) / 2;
212 int y = (GetSystemMetrics(SM_CYSCREEN) - h) / 2;
214 char window_title[64];
215 seprintf(window_title,
lastof(window_title),
"OpenTTD %s", _openttd_revision);
217 this->
main_wnd = CreateWindow(L
"OTTD",
OTTD2FS(window_title).c_str(), style, x, y, w, h, 0, 0, GetModuleHandle(
nullptr),
this);
219 ShowWindow(this->
main_wnd, showstyle);
232 static WChar prev_char = 0;
236 if (prev_char != 0)
Debug(driver, 1,
"Got two UTF-16 lead surrogates, dropping the first one");
237 prev_char = charcode;
242 if (prev_char != 0) {
246 Debug(driver, 1,
"Got an UTF-16 lead surrogate without a trail surrogate, dropping the lead surrogate");
259 return (_imm_props & IME_PROP_AT_CARET) && !(_imm_props & IME_PROP_SPECIAL_UI);
265 HIMC hIMC = ImmGetContext(hwnd);
268 cf.dwStyle = CFS_POINT;
273 cf.ptCurrentPos.x = _focused_window->
left + pt.x;
274 cf.ptCurrentPos.y = _focused_window->
top + pt.y;
276 cf.ptCurrentPos.x = 0;
277 cf.ptCurrentPos.y = 0;
279 ImmSetCompositionWindow(hIMC, &cf);
281 ImmReleaseContext(hwnd, hIMC);
287 HIMC hIMC = ImmGetContext(hwnd);
291 cf.dwStyle = CFS_EXCLUDE;
295 cf.ptCurrentPos.x = _focused_window->
left + pt.x;
296 cf.ptCurrentPos.y = _focused_window->
top + pt.y;
298 cf.rcArea.left = _focused_window->
left;
299 cf.rcArea.top = _focused_window->
top;
300 cf.rcArea.right = _focused_window->
left + _focused_window->
width;
301 cf.rcArea.bottom = _focused_window->
top + _focused_window->
height;
309 cf.ptCurrentPos.x = 0;
310 cf.ptCurrentPos.y = 0;
311 SetRectEmpty(&cf.rcArea);
313 ImmSetCandidateWindow(hIMC, &cf);
315 ImmReleaseContext(hwnd, hIMC);
321 HIMC hIMC = ImmGetContext(hwnd);
324 if (lParam & GCS_RESULTSTR) {
326 LONG len = ImmGetCompositionString(hIMC, GCS_RESULTSTR,
nullptr, 0);
327 wchar_t *str = (
wchar_t *)_alloca(len +
sizeof(
wchar_t));
328 len = ImmGetCompositionString(hIMC, GCS_RESULTSTR, str, len);
329 str[len /
sizeof(wchar_t)] =
'\0';
339 lParam &= ~(GCS_RESULTSTR | GCS_RESULTCLAUSE | GCS_RESULTREADCLAUSE | GCS_RESULTREADSTR);
344 LONG len = ImmGetCompositionString(hIMC, GCS_COMPSTR,
nullptr, 0);
345 wchar_t *str = (
wchar_t *)_alloca(len +
sizeof(
wchar_t));
346 len = ImmGetCompositionString(hIMC, GCS_COMPSTR, str, len);
347 str[len /
sizeof(wchar_t)] =
'\0';
350 static char utf8_buf[1024];
354 LONG caret_bytes = ImmGetCompositionString(hIMC, GCS_CURSORPOS,
nullptr, 0);
355 const char *caret = utf8_buf;
356 for (
const wchar_t *c = str; *c !=
'\0' && *caret !=
'\0' && caret_bytes > 0; c++, caret_bytes--) {
370 lParam &= ~(GCS_COMPSTR | GCS_COMPATTR | GCS_COMPCLAUSE | GCS_CURSORPOS | GCS_DELTASTART);
373 ImmReleaseContext(hwnd, hIMC);
375 return lParam != 0 ? DefWindowProc(hwnd, WM_IME_COMPOSITION, wParam, lParam) : 0;
381 HIMC hIMC = ImmGetContext(hwnd);
382 if (hIMC != NULL) ImmNotifyIME(hIMC, NI_COMPOSITIONSTR, CPS_CANCEL, 0);
383 ImmReleaseContext(hwnd, hIMC);
388 LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
390 static uint32 keycode = 0;
391 static bool console =
false;
397 SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)((LPCREATESTRUCT)lParam)->lpCreateParams);
405 GetUpdateRect(hwnd, &r, FALSE);
406 video_driver->
MakeDirty(r.left, r.top, r.right - r.left, r.bottom - r.top);
408 ValidateRect(hwnd,
nullptr);
412 case WM_PALETTECHANGED:
413 if ((HWND)wParam == hwnd)
return 0;
416 case WM_QUERYNEWPALETTE:
421 HandleExitGameRequest();
462 int x = (int16)LOWORD(lParam);
463 int y = (int16)HIWORD(lParam);
471 tme.cbSize =
sizeof(tme);
472 tme.dwFlags = TME_LEAVE;
473 tme.hwndTrack = hwnd;
475 TrackMouseEvent(&tme);
482 while (PeekMessage(&m, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE | PM_NOYIELD | PM_QS_INPUT)) {
483 x = (int16)LOWORD(m.lParam);
484 y = (int16)HIWORD(m.lParam);
490 pt.x = _cursor.
pos.x;
491 pt.y = _cursor.
pos.y;
492 ClientToScreen(hwnd, &pt);
493 SetCursorPos(pt.x, pt.y);
500 case WM_INPUTLANGCHANGE:
504 case WM_IME_SETCONTEXT:
509 case WM_IME_STARTCOMPOSITION:
514 case WM_IME_COMPOSITION:
517 case WM_IME_ENDCOMPOSITION:
528 console =
GB(lParam, 16, 8) == 41;
532 uint scancode =
GB(lParam, 16, 8);
533 uint charcode = wParam;
537 if (console && scancode == 41) {
544 uint cur_keycode = keycode;
552 uint scancode =
GB(lParam, 16, 8);
553 keycode = scancode == 41 ? (uint)WKC_BACKQUOTE : MapWindowsKey(wParam);
555 uint charcode = MapVirtualKey(wParam, MAPVK_VK_TO_CHAR);
566 if (
HasBit(charcode, 31) && !console) {
567 if (scancode == 41) {
576 uint cur_keycode = keycode;
606 if (wParam != SIZE_MINIMIZED) {
609 _window_maximize = (wParam == SIZE_MAXIMIZED || (_window_maximize && _fullscreen));
610 if (_window_maximize || _fullscreen) _bck_resolution =
_cur_resolution;
611 video_driver->ClientSizeChanged(LOWORD(lParam), HIWORD(lParam));
616 RECT *r = (RECT*)lParam;
620 SetRect(&r2, 0, 0, 0, 0);
621 AdjustWindowRect(&r2, GetWindowLong(hwnd, GWL_STYLE), FALSE);
623 w = r->right - r->left - (r2.right - r2.left);
624 h = r->bottom - r->top - (r2.bottom - r2.top);
627 SetRect(&r2, 0, 0, w, h);
629 AdjustWindowRect(&r2, GetWindowLong(hwnd, GWL_STYLE), FALSE);
630 w = r2.right - r2.left;
631 h = r2.bottom - r2.top;
635 r->bottom = r->top + h;
638 case WMSZ_BOTTOMLEFT:
639 r->bottom = r->top + h;
640 r->left = r->right - w;
643 case WMSZ_BOTTOMRIGHT:
644 r->bottom = r->top + h;
645 r->right = r->left + w;
649 r->left = r->right - w;
653 r->right = r->left + w;
657 r->top = r->bottom - h;
661 r->top = r->bottom - h;
662 r->left = r->right - w;
666 r->top = r->bottom - h;
667 r->right = r->left + w;
674 #if !defined(WM_MOUSEWHEEL)
675 # define WM_MOUSEWHEEL 0x020A
677 #if !defined(GET_WHEEL_DELTA_WPARAM)
678 # define GET_WHEEL_DELTA_WPARAM(wparam) ((short)HIWORD(wparam))
681 case WM_MOUSEWHEEL: {
682 int delta = GET_WHEEL_DELTA_WPARAM(wParam);
686 }
else if (delta > 0) {
704 if (_exit_game)
break;
706 bool active = (LOWORD(wParam) != WA_INACTIVE);
707 bool minimized = (HIWORD(wParam) != 0);
709 if (active && minimized) {
712 ShowWindow(hwnd, SW_RESTORE);
715 }
else if (!active && !minimized) {
717 ShowWindow(hwnd, SW_MINIMIZE);
718 ChangeDisplaySettings(
nullptr, 0);
725 return DefWindowProc(hwnd, msg, wParam, lParam);
728 static void RegisterWndClass()
730 static bool registered =
false;
732 if (registered)
return;
734 HINSTANCE hinst = GetModuleHandle(
nullptr);
741 LoadIcon(hinst, MAKEINTRESOURCE(100)),
742 LoadCursor(
nullptr, IDC_ARROW),
749 if (!RegisterClass(&wnd))
usererror(
"RegisterClass failed");
752 static const Dimension default_resolutions[] = {
766 static void FindResolutions(uint8 bpp)
771 for (uint i = 0; EnumDisplaySettings(
nullptr, i, &dm) != 0; i++) {
772 if (dm.dmBitsPerPel != bpp || dm.dmPelsWidth < 640 || dm.dmPelsHeight < 480)
continue;
774 _resolutions.emplace_back(dm.dmPelsWidth, dm.dmPelsHeight);
779 _resolutions.assign(std::begin(default_resolutions), std::end(default_resolutions));
785 void VideoDriver_Win32Base::Initialize()
803 if (this->
fullscreen) ChangeDisplaySettings(
nullptr, 0);
815 this->
MakeDirty(0, 0, _screen.width, _screen.height);
836 (GetAsyncKeyState(VK_LEFT) < 0 ? 1 : 0) +
837 (GetAsyncKeyState(VK_UP) < 0 ? 2 : 0) +
838 (GetAsyncKeyState(VK_RIGHT) < 0 ? 4 : 0) +
839 (GetAsyncKeyState(VK_DOWN) < 0 ? 8 : 0);
851 if (!PeekMessage(&mesg,
nullptr, 0, 0, PM_REMOVE))
return false;
855 DispatchMessage(&mesg);
865 if (_exit_game)
break;
874 void VideoDriver_Win32Base::ClientSizeChanged(
int w,
int h,
bool force)
888 if (_window_maximize) ShowWindow(this->
main_wnd, SW_SHOWNORMAL);
911 static BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor, HDC hDC, LPRECT rc, LPARAM data)
913 auto &list = *
reinterpret_cast<std::vector<int>*
>(data);
915 MONITORINFOEX monitorInfo = {};
916 monitorInfo.cbSize =
sizeof(MONITORINFOEX);
917 GetMonitorInfo(hMonitor, &monitorInfo);
919 DEVMODE devMode = {};
920 devMode.dmSize =
sizeof(DEVMODE);
921 devMode.dmDriverExtra = 0;
922 EnumDisplaySettings(monitorInfo.szDevice, ENUM_CURRENT_SETTINGS, &devMode);
924 if (devMode.dmDisplayFrequency != 0) list.push_back(devMode.dmDisplayFrequency);
930 std::vector<int> rates = {};
931 EnumDisplayMonitors(
nullptr,
nullptr, MonitorEnumProc,
reinterpret_cast<LPARAM
>(&rates));
937 return {
static_cast<uint
>(GetSystemMetrics(SM_CXSCREEN)),
static_cast<uint
>(GetSystemMetrics(SM_CYSCREEN)) };
942 typedef UINT (WINAPI *PFNGETDPIFORWINDOW)(HWND hwnd);
943 typedef UINT (WINAPI *PFNGETDPIFORSYSTEM)(VOID);
944 typedef HRESULT (WINAPI *PFNGETDPIFORMONITOR)(HMONITOR hMonitor,
int dpiType, UINT *dpiX, UINT *dpiY);
946 static PFNGETDPIFORWINDOW _GetDpiForWindow =
nullptr;
947 static PFNGETDPIFORSYSTEM _GetDpiForSystem =
nullptr;
948 static PFNGETDPIFORMONITOR _GetDpiForMonitor =
nullptr;
950 static bool init_done =
false;
955 _GetDpiForWindow = _user32.GetProcAddress(
"GetDpiForWindow");
956 _GetDpiForSystem = _user32.GetProcAddress(
"GetDpiForSystem");
957 _GetDpiForMonitor = _shcore.GetProcAddress(
"GetDpiForMonitor");
962 if (cur_dpi == 0 && _GetDpiForWindow !=
nullptr && this->
main_wnd !=
nullptr) {
964 cur_dpi = _GetDpiForWindow(this->
main_wnd);
966 if (cur_dpi == 0 && _GetDpiForMonitor !=
nullptr && this->
main_wnd !=
nullptr) {
969 if (SUCCEEDED(_GetDpiForMonitor(MonitorFromWindow(this->
main_wnd, MONITOR_DEFAULTTOPRIMARY), 0 , &dpiX, &dpiY))) {
973 if (cur_dpi == 0 && _GetDpiForSystem !=
nullptr) {
975 cur_dpi = _GetDpiForSystem();
978 return cur_dpi > 0 ? cur_dpi / 96.0f : 1.0f;
987 assert(_screen.dst_ptr !=
nullptr);
994 assert(_screen.dst_ptr !=
nullptr);
995 if (_screen.dst_ptr !=
nullptr) {
998 _screen.dst_ptr =
nullptr;
1013 this->MakePalette();
1036 w = std::max(w, 64);
1037 h = std::max(h, 64);
1039 if (!force && w == _screen.width && h == _screen.height)
return false;
1041 BITMAPINFO *bi = (BITMAPINFO *)alloca(
sizeof(BITMAPINFOHEADER) +
sizeof(RGBQUAD) * 256);
1042 memset(bi, 0,
sizeof(BITMAPINFOHEADER) +
sizeof(RGBQUAD) * 256);
1043 bi->bmiHeader.biSize =
sizeof(BITMAPINFOHEADER);
1045 bi->bmiHeader.biWidth = this->
width = w;
1046 bi->bmiHeader.biHeight = -(this->
height = h);
1048 bi->bmiHeader.biPlanes = 1;
1049 bi->bmiHeader.biBitCount = bpp;
1050 bi->bmiHeader.biCompression = BI_RGB;
1055 this->
dib_sect = CreateDIBSection(dc, bi, DIB_RGB_COLORS, (VOID **)&this->
buffer_bits,
nullptr, 0);
1060 _screen.pitch = (bpp == 8) ?
Align(w, 4) : w;
1073 void VideoDriver_Win32GDI::MakePalette()
1077 LOGPALETTE *pal = (LOGPALETTE*)alloca(
sizeof(LOGPALETTE) + (256 - 1) *
sizeof(PALETTEENTRY));
1079 pal->palVersion = 0x300;
1080 pal->palNumEntries = 256;
1082 for (uint i = 0; i != 256; i++) {
1086 pal->palPalEntry[i].peFlags = 0;
1093 void VideoDriver_Win32GDI::UpdatePalette(HDC dc, uint start, uint count)
1097 for (uint i = 0; i != count; i++) {
1101 rgb[i].rgbReserved = 0;
1104 SetDIBColorTable(dc, start, count, rgb);
1109 HDC hDC = GetWindowDC(hWnd);
1110 HPALETTE hOldPalette = SelectPalette(hDC, this->
gdi_palette, FALSE);
1111 UINT nChanged = RealizePalette(hDC);
1113 SelectPalette(hDC, hOldPalette, TRUE);
1114 ReleaseDC(hWnd, hDC);
1115 if (nChanged != 0) this->
MakeDirty(0, 0, _screen.width, _screen.height);
1125 HDC dc2 = CreateCompatibleDC(dc);
1127 HBITMAP old_bmp = (HBITMAP)SelectObject(dc2, this->
dib_sect);
1128 HPALETTE old_palette = SelectPalette(dc, this->
gdi_palette, FALSE);
1152 BitBlt(dc, 0, 0, this->
width, this->
height, dc2, 0, 0, SRCCOPY);
1153 SelectPalette(dc, old_palette, TRUE);
1154 SelectObject(dc2, old_bmp);
1165 int VideoDriver_Win32GDI::RedrawScreenDebug()
1184 #include "../3rdparty/opengl/glext.h"
1185 #include "../3rdparty/opengl/wglext.h"
1188 #ifndef PFD_SUPPORT_COMPOSITION
1189 # define PFD_SUPPORT_COMPOSITION 0x00008000
1192 static PFNWGLCREATECONTEXTATTRIBSARBPROC _wglCreateContextAttribsARB =
nullptr;
1193 static PFNWGLSWAPINTERVALEXTPROC _wglSwapIntervalEXT =
nullptr;
1194 static bool _hasWGLARBCreateContextProfile =
false;
1199 OGLProc ret =
reinterpret_cast<OGLProc
>(wglGetProcAddress(proc));
1200 if (ret ==
nullptr) {
1202 ret =
reinterpret_cast<OGLProc
>(GetProcAddress(GetModuleHandle(L
"opengl32"), proc));
1213 static const char *SelectPixelFormat(HDC dc,
bool fullscreen)
1215 PIXELFORMATDESCRIPTOR pfd = {
1216 sizeof(PIXELFORMATDESCRIPTOR),
1218 PFD_DRAW_TO_WINDOW |
1219 PFD_SUPPORT_OPENGL |
1224 0, 0, 0, 0, 0, 0, 0, 0,
1232 if (IsWindowsVistaOrGreater()) pfd.dwFlags |= PFD_SUPPORT_COMPOSITION;
1235 int format = ChoosePixelFormat(dc, &pfd);
1236 if (format == 0)
return "No suitable pixel format found";
1237 if (!SetPixelFormat(dc, format, &pfd))
return "Can't set pixel format";
1243 static void LoadWGLExtensions()
1250 HWND wnd = CreateWindow(_T(
"STATIC"), _T(
"dummy"), WS_OVERLAPPEDWINDOW, 0, 0, 0, 0,
nullptr,
nullptr, GetModuleHandle(
nullptr),
nullptr);
1251 HDC dc = GetDC(wnd);
1254 if (SelectPixelFormat(dc,
false) ==
nullptr) {
1256 HGLRC rc = wglCreateContext(dc);
1257 if (rc !=
nullptr) {
1258 wglMakeCurrent(dc, rc);
1262 #pragma GCC diagnostic push
1263 #pragma GCC diagnostic ignored "-Wcast-function-type"
1267 PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress(
"wglGetExtensionsStringARB");
1268 if (wglGetExtensionsStringARB !=
nullptr) {
1269 const char *wgl_exts = wglGetExtensionsStringARB(dc);
1272 _wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress(
"wglCreateContextAttribsARB");
1276 _wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress(
"wglSwapIntervalEXT");
1281 #pragma GCC diagnostic pop
1283 wglMakeCurrent(
nullptr,
nullptr);
1284 wglDeleteContext(rc);
1292 static FVideoDriver_Win32OpenGL iFVideoDriver_Win32OpenGL;
1294 const char *VideoDriver_Win32OpenGL::Start(
const StringList ¶m)
1300 LoadWGLExtensions();
1303 this->MakeWindow(_fullscreen);
1306 const char *err = this->AllocateContext();
1307 if (err !=
nullptr) {
1313 this->ClientSizeChanged(this->width, this->height,
true);
1315 if (_screen.dst_ptr ==
nullptr) {
1318 return "Can't get pointer to screen buffer";
1321 this->ReleaseVideoPointer();
1330 void VideoDriver_Win32OpenGL::Stop()
1332 this->DestroyContext();
1336 void VideoDriver_Win32OpenGL::DestroyContext()
1340 wglMakeCurrent(
nullptr,
nullptr);
1341 if (this->gl_rc !=
nullptr) {
1342 wglDeleteContext(this->gl_rc);
1343 this->gl_rc =
nullptr;
1345 if (this->dc !=
nullptr) {
1346 ReleaseDC(this->main_wnd, this->dc);
1351 void VideoDriver_Win32OpenGL::ToggleVsync(
bool vsync)
1353 if (_wglSwapIntervalEXT !=
nullptr) {
1354 _wglSwapIntervalEXT(vsync);
1356 Debug(driver, 0,
"OpenGL: Vsync requested, but not supported by driver");
1360 const char *VideoDriver_Win32OpenGL::AllocateContext()
1362 this->dc = GetDC(this->main_wnd);
1364 const char *err = SelectPixelFormat(this->dc, this->fullscreen);
1365 if (err !=
nullptr)
return err;
1370 if (_wglCreateContextAttribsARB !=
nullptr) {
1373 WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
1374 WGL_CONTEXT_MINOR_VERSION_ARB, 5,
1375 WGL_CONTEXT_FLAGS_ARB, _debug_driver_level >= 8 ? WGL_CONTEXT_DEBUG_BIT_ARB : 0,
1376 _hasWGLARBCreateContextProfile ? WGL_CONTEXT_PROFILE_MASK_ARB : 0, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
1379 rc = _wglCreateContextAttribsARB(this->dc,
nullptr, attribs);
1381 if (rc ==
nullptr) {
1385 rc = _wglCreateContextAttribsARB(this->dc,
nullptr, attribs);
1389 if (rc ==
nullptr) {
1391 rc = wglCreateContext(this->dc);
1392 if (rc ==
nullptr)
return "Can't create OpenGL context";
1394 if (!wglMakeCurrent(this->dc, rc))
return "Can't active GL context";
1402 bool VideoDriver_Win32OpenGL::ToggleFullscreen(
bool full_screen)
1404 if (_screen.dst_ptr !=
nullptr) this->ReleaseVideoPointer();
1405 this->DestroyContext();
1407 res &= this->AllocateContext() ==
nullptr;
1408 this->ClientSizeChanged(this->width, this->height,
true);
1412 bool VideoDriver_Win32OpenGL::AfterBlitterChange()
1415 this->ClientSizeChanged(this->width, this->height,
true);
1419 void VideoDriver_Win32OpenGL::PopulateSystemSprites()
1424 void VideoDriver_Win32OpenGL::ClearSystemSprites()
1429 bool VideoDriver_Win32OpenGL::AllocateBackingStore(
int w,
int h,
bool force)
1431 if (!force && w == _screen.width && h == _screen.height)
return false;
1433 this->width = w = std::max(w, 64);
1434 this->height = h = std::max(h, 64);
1436 if (this->gl_rc ==
nullptr)
return false;
1438 if (_screen.dst_ptr !=
nullptr) this->ReleaseVideoPointer();
1440 this->dirty_rect = {};
1442 SwapBuffers(this->dc);
1443 _screen.dst_ptr = this->GetVideoPointer();
1448 void *VideoDriver_Win32OpenGL::GetVideoPointer()
1456 void VideoDriver_Win32OpenGL::ReleaseVideoPointer()
1460 this->dirty_rect = {};
1461 _screen.dst_ptr =
nullptr;
1462 this->anim_buffer =
nullptr;
1465 void VideoDriver_Win32OpenGL::Paint()
1484 SwapBuffers(this->dc);