Refresh window parameters on SwapBuffers as well as MakeCurrent

* There's no guarantee that MakeCurrent will always be called after a resize,
  the same context could be activated then left active.
This commit is contained in:
baldurk
2018-11-28 20:37:49 +00:00
parent 57f4e4bf16
commit 7f533b6b29
4 changed files with 73 additions and 29 deletions
+38 -20
View File
@@ -72,6 +72,34 @@ public:
return false;
}
void RefreshWindowParameters(const GLWindowingData &data)
{
EGLDisplay display = data.egl_dpy;
EGLContext ctx = data.egl_ctx;
EGLSurface draw = data.egl_wnd;
if(ctx && draw)
{
GLInitParams &params = driver.GetInitParams(data);
int height, width;
EGL.QuerySurface(display, draw, EGL_HEIGHT, &height);
EGL.QuerySurface(display, draw, EGL_WIDTH, &width);
int colorspace = 0;
EGL.QuerySurface(display, draw, EGL_GL_COLORSPACE, &colorspace);
// GL_SRGB8_ALPHA8 is specified as color-renderable, unlike GL_SRGB8.
bool isSRGB = params.colorBits == 32 && colorspace == EGL_GL_COLORSPACE_SRGB;
bool isYFlipped = IsYFlipped(display, draw);
params.width = width;
params.height = height;
params.isSRGB = isSRGB;
params.isYFlipped = isYFlipped;
}
}
} eglhook;
HOOK_EXPORT EGLDisplay EGLAPIENTRY eglGetDisplay_renderdoc_hooked(EGLNativeDisplayType display)
@@ -300,26 +328,7 @@ HOOK_EXPORT EGLBoolean EGLAPIENTRY eglMakeCurrent_renderdoc_hooked(EGLDisplay di
eglhook.driver.ActivateContext(data);
if(ctx && draw)
{
GLInitParams &params = eglhook.driver.GetInitParams(data);
int height, width;
EGL.QuerySurface(display, draw, EGL_HEIGHT, &height);
EGL.QuerySurface(display, draw, EGL_WIDTH, &width);
int colorspace = 0;
EGL.QuerySurface(display, draw, EGL_GL_COLORSPACE, &colorspace);
// GL_SRGB8_ALPHA8 is specified as color-renderable, unlike GL_SRGB8.
bool isSRGB = params.colorBits == 32 && colorspace == EGL_GL_COLORSPACE_SRGB;
bool isYFlipped = eglhook.IsYFlipped(display, draw);
params.width = width;
params.height = height;
params.isSRGB = isSRGB;
params.isYFlipped = isYFlipped;
}
eglhook.RefreshWindowParameters(data);
}
return ret;
@@ -339,7 +348,16 @@ HOOK_EXPORT EGLBoolean EGLAPIENTRY eglSwapBuffers_renderdoc_hooked(EGLDisplay dp
eglhook.driver.SetDriverType(RDCDriver::OpenGLES);
if(!eglhook.driver.UsesVRFrameMarkers())
{
GLWindowingData data;
data.egl_dpy = dpy;
data.egl_wnd = surface;
data.egl_ctx = EGL.GetCurrentContext();
eglhook.RefreshWindowParameters(data);
eglhook.driver.SwapBuffers(surface);
}
return EGL.SwapBuffers(dpy, surface);
}
+2
View File
@@ -37,6 +37,7 @@ typedef int (*PFN_glXQueryContext)(Display *dpy, GLXContext ctx, int attribute,
typedef Bool (*PFN_glXIsDirect)(Display *dpy, GLXContext ctx);
typedef __GLXextFuncPtr (*PFN_glXGetProcAddress)(const GLubyte *);
typedef __GLXextFuncPtr (*PFN_glXGetProcAddressARB)(const GLubyte *);
typedef GLXContext (*PFN_glXGetCurrentContext)();
typedef const char *(*PFN_glXQueryExtensionsString)(Display *dpy, int screen);
typedef PFNGLXGETVISUALFROMFBCONFIGPROC PFN_glXGetVisualFromFBConfig;
typedef PFNGLXMAKECONTEXTCURRENTPROC PFN_glXMakeContextCurrent;
@@ -74,6 +75,7 @@ typedef void (*PFN_glEnd)();
FUNC(glXDestroyWindow);
#define GLX_NONHOOKED_SYMBOLS(FUNC) \
FUNC(glXGetCurrentContext); \
FUNC(glXGetConfig); \
FUNC(glXQueryContext); \
FUNC(glXIsDirect); \
+10
View File
@@ -435,6 +435,16 @@ HOOK_EXPORT void glXSwapBuffers_renderdoc_hooked(Display *dpy, GLXDrawable drawa
SCOPED_LOCK(glLock);
{
GLWindowingData data;
data.dpy = dpy;
data.wnd = drawable;
data.ctx = GLX.glXGetCurrentContext();
data.cfg = NULL;
glxhook.UpdateWindowSize(data, dpy, drawable);
}
glxhook.driver.SwapBuffers((void *)drawable);
GLX.glXSwapBuffers(dpy, drawable);
+23 -9
View File
@@ -47,6 +47,7 @@ public:
std::set<HGLRC> contexts;
void RefreshWindowParameters(const GLWindowingData &data);
void ProcessSwapBuffers(HDC dc);
void PopulateFromContext(HDC dc, HGLRC rc);
GLInitParams GetInitParamsForDC(HDC dc);
@@ -137,6 +138,19 @@ GLInitParams WGLHook::GetInitParamsForDC(HDC dc)
return ret;
}
void WGLHook::RefreshWindowParameters(const GLWindowingData &data)
{
if(haveContextCreation && data.ctx && data.wnd)
{
RECT r;
GetClientRect(data.wnd, &r);
GLInitParams &params = driver.GetInitParams(data);
params.width = r.right - r.left;
params.height = r.bottom - r.top;
}
}
void WGLHook::ProcessSwapBuffers(HDC dc)
{
HWND w = WindowFromDC(dc);
@@ -145,6 +159,13 @@ void WGLHook::ProcessSwapBuffers(HDC dc)
if(w != NULL && haveContextCreation && !swapRecurse)
{
GLWindowingData data;
data.DC = dc;
data.wnd = w;
data.ctx = WGL.wglGetCurrentContext();
RefreshWindowParameters(data);
{
SCOPED_LOCK(glLock);
driver.SwapBuffers(w);
@@ -369,17 +390,10 @@ static BOOL WINAPI wglMakeCurrent_hooked(HDC dc, HGLRC rc)
data.wnd = WindowFromDC(dc);
data.ctx = rc;
wglhook.RefreshWindowParameters(data);
if(wglhook.haveContextCreation && data.ctx && data.wnd)
{
RECT r;
GetClientRect(data.wnd, &r);
wglhook.driver.ActivateContext(data);
GLInitParams &params = wglhook.driver.GetInitParams(data);
params.width = r.right - r.left;
params.height = r.bottom - r.top;
}
}
SetLastError(err);