, OpenGL - API-, , . , , - , . , , , , , .
: wglSwapBuffers ( glXSwapBuffers X11, eglSwapBuffers EGL - Windows ).
, , SwapBuffers. .
OpenGL , , . , OpenGL, , . , SwapBuffers :
BOOL WINAPI (*host_SwapBuffers)(HDC);
HGLRC hook_last_rc_created = NULL;
std::map<int, HGLRC> hook_pixelformat_to_rc;
void init_RC();
void init_GL();
void draw_overlay(RECT const *rect);
BOOL WINAPI hook_SwapBuffers(HDC dc)
{
if( !dc ) {
goto terminate;
}
int const pixelformat = GetPixelFormat(dc);
HGLRC hook_rc;
if( 0 == hook_pixelformat_to_rc.count(pixelformat) ) {
hook_rc = wglCreateContext(dc);
if( !hook_rc ) {
goto terminate;
}
hook_pixelformat_to_rc[pixelformat] = hook_rc;
init_RC();
if( hook_last_rc_created ) {
wglShareLists(hook_last_rc_created, hook_rc);
}
else {
init_GL();
}
hook_last_rc_created = hook_rc;
}
else {
hook_rc = hook_pixelformat_to_rc[pixelformat];
}
HGLRC const host_rc = wglGetCurrentContext();
HWND const wnd = WindowFromDC(dc);
RECT wnd_rect;
GetClientRect(wnd, &wnd_rect);
wglMakeCurrent(dc, hook_rc);
draw_overlay(&wnd_rect);
wglMakeCurrent(dc, host_rc);
terminate:
return host_SwapBuffers(hdc);
}