GLCtrl: ExecuteGL in Win32

git-svn-id: svn://ultimatepp.org/upp/trunk@13526 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2019-08-09 07:23:01 +00:00
parent bbdc24dfab
commit 55754feb4d
2 changed files with 32 additions and 9 deletions

View file

@ -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(); }

View file

@ -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
}