From 55754feb4dfdce736d4d075b926b62ee07500a98 Mon Sep 17 00:00:00 2001 From: cxl Date: Fri, 9 Aug 2019 07:23:01 +0000 Subject: [PATCH] GLCtrl: ExecuteGL in Win32 git-svn-id: svn://ultimatepp.org/upp/trunk@13526 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/GLCtrl/GLCtrl.h | 5 +++++ uppsrc/GLCtrl/Win32GLCtrl.cpp | 36 ++++++++++++++++++++++++++--------- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/uppsrc/GLCtrl/GLCtrl.h b/uppsrc/GLCtrl/GLCtrl.h index 3589aa439..7677d10d7 100644 --- a/uppsrc/GLCtrl/GLCtrl.h +++ b/uppsrc/GLCtrl/GLCtrl.h @@ -80,6 +80,9 @@ private: void Destroy(); void ActivateContext(); + + void ExecuteGL(HDC hdc, Event<> paint, bool swap_buffers); + void ExecuteGL(Event<> paint, bool swap_buffers); }; #endif @@ -129,6 +132,8 @@ public: static void SetCurrentViewport(); // intended to restore viewport after changing it in e.g. TextureDraw GLCtrl& RedirectMouse(Ctrl *target) { mouseTarget = target; return *this; } + + void ExecuteGL(Event<> gl, bool swap_buffers = false); GLCtrl() { Init(); } diff --git a/uppsrc/GLCtrl/Win32GLCtrl.cpp b/uppsrc/GLCtrl/Win32GLCtrl.cpp index 708682b5f..4367690d6 100644 --- a/uppsrc/GLCtrl/Win32GLCtrl.cpp +++ b/uppsrc/GLCtrl/Win32GLCtrl.cpp @@ -100,21 +100,34 @@ void GLCtrl::GLPane::State(int reason) } } +void GLCtrl::GLPane::ExecuteGL(HDC hDC, Event<> paint, bool swap_buffers) +{ + wglMakeCurrent(hDC, s_openGLContext); + paint(); + if(swap_buffers) + SwapBuffers(hDC); + else + glFlush(); + wglMakeCurrent(NULL, NULL); +} + +void GLCtrl::GLPane::ExecuteGL(Event<> paint, bool swap_buffers) +{ + HWND hwnd = GetHWND(); + GLCtrl::CreateContext(); + HDC hDC = GetDC(hwnd); + ExecuteGL(hDC, paint, swap_buffers); + ReleaseDC(hwnd, hDC); +} + LRESULT GLCtrl::GLPane::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { if(message == WM_PAINT && s_openGLContext) { PAINTSTRUCT ps; HWND hwnd = GetHWND(); BeginPaint(hwnd, &ps); - HDC hDC = ps.hdc; - wglMakeCurrent(hDC, s_openGLContext); - ctrl->DoGLPaint(); - if(ctrl->doubleBuffering) - SwapBuffers(hDC); - else - glFlush(); - wglMakeCurrent(NULL, NULL); - ReleaseDC(hwnd, hDC); + ExecuteGL(ps.hdc, [&] { ctrl->DoGLPaint(); }, ctrl->doubleBuffering); + ReleaseDC(hwnd, ps.hdc); EndPaint(hwnd, &ps); return 0; } @@ -122,6 +135,11 @@ LRESULT GLCtrl::GLPane::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) return DHCtrl::WindowProc(message, wParam, lParam); } +void GLCtrl::ExecuteGL(Event<> paint, bool swap_buffers) +{ + pane.ExecuteGL(paint, swap_buffers); +} + #endif }