Win32-Acrylic-Effect icon indicating copy to clipboard operation
Win32-Acrylic-Effect copied to clipboard

Usage in OpenGL application

Open MayaankAshok opened this issue 3 years ago • 7 comments

This works brilliantly in a stand-alone window, however when I try to implement it in an OpenGL & GLFW window , any objects drawn by OpenGL do not appear . Any ideas what could be wrong? (Windows 10 21H1 )

MayaankAshok avatar Feb 04 '22 06:02 MayaankAshok

This problem is caused by airspace issue. actually whatever you are drawing on to the window is drawn under the blurred visual. this is an issue that Microsoft couldn't even fix until now. Direct Composition Visuals always stays on top in the window

selastingeorge avatar Feb 04 '22 06:02 selastingeorge

Would it be possible to submit the opengl buffer directly into the direct composition? so that we control the z-index of each buffer?

MayaankAshok avatar Feb 04 '22 06:02 MayaankAshok

i am not much familiar with opengl, but if it is possible for you to draw opengl content into ID2D1Bitmap1 then you can share it to IDCompositionVisual.

eg: in AcrylicComositor.cpp i have used fallbackBitmap that is ID2D1Bitmap1 and it contains d2d content.

The IDComposition has many limitations and the new Windows.UI.Composition will be a better option. The only way to overcome Airspace issue would be by overlapping windows like i did here: Fluent Compositor Preview

selastingeorge avatar Feb 04 '22 06:02 selastingeorge

Interesting, I'm using Vulkan & GLFW, and after some fighting with how my setup works, I finally got it to work, but I too also noticed that the Direct Composition is always on top over the rendered frame... I'm sure there's a way to draw the Vulkan content into a ID2D1Bitmap1, so I'll be investigating into that. How would the ID2D1Bitmap1 data be used? Is there a function to pass it or something?

Stanlyhalo avatar Feb 17 '23 17:02 Stanlyhalo

It's been a little long since I have worked on this, We can only place a IDCompositionVisual on top of another IDCompositionVisual , it's not possible to draw stuff directly on IDCompositionVisual, so I used D2D to draw content on to ID2D1Bitmap1 and presented it to the SwapChain that I have created and use the content of that swapchain as the content for IDCompositionVisual

Example: fallbackVisual->SetContent(swapChain.Get());

This version of DirectComposition is not used now a days, everyone is moving to WinUI3 or WinRT API's

selastingeorge avatar Feb 18 '23 06:02 selastingeorge

Interesting, I'm using glfw so I'm not sure which version it natively uses for windows in regards to winapi, maybe it's using winrt, idk. But maybe there's a way to render a DirectComposition to an offscreen texture, not render it over everything, and use that as a texture for the background of my application.

Stanlyhalo avatar Feb 18 '23 16:02 Stanlyhalo

But maybe there's a way to render a DirectComposition to an offscreen texture

I think that is not possible.

According to Microsoft docs:

A visual tree must be bound to a window before any of the tree's visuals can be displayed on the screen. The window, called the composition target window, can be a top-level window or a child window. Also, the composition target window can be a layered window; that is, it can have the WS_EX_LAYERED window style.

DirectComposition allows an application to bind a maximum of two visual trees to each window. The visual trees include one that is composed on top of the window itself, but behind all of the window’s child windows, and another that is composed on top of the window and on top of the child windows. In other words, each window has four conceptual layers, and all layers are clipped to the target window's visible region.

Source

selastingeorge avatar Feb 18 '23 17:02 selastingeorge