mirror of
https://github.com/glfw/glfw.git
synced 2026-09-20 16:30:45 +00:00
Add GLFW_TRANSPARENT attribute and documentation
This completes support for window framebuffer transparency on Windows, macOS and X11. Note that the hint/attribute may be renamed before release to clarify its relationship to GLFW_OPACITY. Fixes #197. Closes #1079. Related to #663. Related to #715. Related to #723. Related to #1078.
This commit is contained in:
+18
-40
@@ -87,21 +87,13 @@ static int getEGLConfigAttrib(EGLConfig config, int attrib)
|
||||
//
|
||||
static GLFWbool chooseEGLConfig(const _GLFWctxconfig* ctxconfig,
|
||||
const _GLFWfbconfig* desired,
|
||||
EGLConfig* result,
|
||||
GLFWbool findTransparent)
|
||||
EGLConfig* result)
|
||||
{
|
||||
EGLConfig* nativeConfigs;
|
||||
_GLFWfbconfig* usableConfigs;
|
||||
const _GLFWfbconfig* closest;
|
||||
int i, nativeCount, usableCount;
|
||||
|
||||
#if defined(_GLFW_X11)
|
||||
XVisualInfo visualTemplate = {0};
|
||||
if ( !(_glfw.xrender.major || _glfw.xrender.minor) ) {
|
||||
findTransparent = GLFW_FALSE;
|
||||
}
|
||||
#endif // _GLFW_X11
|
||||
|
||||
eglGetConfigs(_glfw.egl.display, NULL, 0, &nativeCount);
|
||||
if (!nativeCount)
|
||||
{
|
||||
@@ -115,7 +107,6 @@ static GLFWbool chooseEGLConfig(const _GLFWctxconfig* ctxconfig,
|
||||
usableConfigs = calloc(nativeCount, sizeof(_GLFWfbconfig));
|
||||
usableCount = 0;
|
||||
|
||||
selectionloop:
|
||||
for (i = 0; i < nativeCount; i++)
|
||||
{
|
||||
const EGLConfig n = nativeConfigs[i];
|
||||
@@ -130,31 +121,24 @@ selectionloop:
|
||||
continue;
|
||||
|
||||
#if defined(_GLFW_X11)
|
||||
XVisualInfo vi = {0};
|
||||
|
||||
// Only consider EGLConfigs with associated Visuals
|
||||
visualTemplate.visualid = getEGLConfigAttrib(n, EGL_NATIVE_VISUAL_ID);
|
||||
if (!visualTemplate.visualid)
|
||||
vi.visualid = getEGLConfigAttrib(n, EGL_NATIVE_VISUAL_ID);
|
||||
if (!vi.visualid)
|
||||
continue;
|
||||
|
||||
if( findTransparent ) {
|
||||
int n_vi;
|
||||
XVisualInfo *visualinfo;
|
||||
XRenderPictFormat *pictFormat;
|
||||
|
||||
visualinfo = XGetVisualInfo(_glfw.x11.display, VisualIDMask, &visualTemplate, &n_vi);
|
||||
if (!visualinfo)
|
||||
continue;
|
||||
|
||||
pictFormat = XRenderFindVisualFormat(_glfw.x11.display, visualinfo->visual);
|
||||
if( !pictFormat ) {
|
||||
XFree( visualinfo );
|
||||
continue;
|
||||
}
|
||||
|
||||
if( !pictFormat->direct.alphaMask ) {
|
||||
XFree( visualinfo );
|
||||
continue;
|
||||
}
|
||||
XFree( visualinfo );
|
||||
if (desired->transparent)
|
||||
{
|
||||
int count;
|
||||
XVisualInfo* vis = XGetVisualInfo(_glfw.x11.display,
|
||||
VisualIDMask, &vi,
|
||||
&count);
|
||||
if (vis)
|
||||
{
|
||||
u->transparent = _glfwIsVisualTransparentX11(vis[0].visual);
|
||||
XFree(vis);
|
||||
}
|
||||
}
|
||||
#endif // _GLFW_X11
|
||||
|
||||
@@ -191,12 +175,6 @@ selectionloop:
|
||||
u->handle = (uintptr_t) n;
|
||||
usableCount++;
|
||||
}
|
||||
// reiterate the selection loop without looking for transparency supporting
|
||||
// formats if no matchig FB configs for a transparent window were found.
|
||||
if( findTransparent && !usableCount ) {
|
||||
findTransparent = GLFW_FALSE;
|
||||
goto selectionloop;
|
||||
}
|
||||
|
||||
closest = _glfwChooseFBConfig(desired, usableConfigs, usableCount);
|
||||
if (closest)
|
||||
@@ -493,7 +471,7 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window,
|
||||
if (ctxconfig->share)
|
||||
share = ctxconfig->share->context.egl.handle;
|
||||
|
||||
if (!chooseEGLConfig(ctxconfig, fbconfig, &config, fbconfig->transparent))
|
||||
if (!chooseEGLConfig(ctxconfig, fbconfig, &config))
|
||||
{
|
||||
_glfwInputError(GLFW_FORMAT_UNAVAILABLE,
|
||||
"EGL: Failed to find a suitable EGLConfig");
|
||||
@@ -738,7 +716,7 @@ GLFWbool _glfwChooseVisualEGL(const _GLFWwndconfig* wndconfig,
|
||||
EGLint visualID = 0, count = 0;
|
||||
const long vimask = VisualScreenMask | VisualIDMask;
|
||||
|
||||
if (!chooseEGLConfig(ctxconfig, fbconfig, &native, fbconfig->transparent))
|
||||
if (!chooseEGLConfig(ctxconfig, fbconfig, &native))
|
||||
{
|
||||
_glfwInputError(GLFW_FORMAT_UNAVAILABLE,
|
||||
"EGL: Failed to find a suitable EGLConfig");
|
||||
|
||||
Reference in New Issue
Block a user