DirectComposition render to texture?
Asked Answered
C

1

7

I would like to have directcomposition render to a texture. Is this possible?

The reason for this is that I would like to be able to render a gpu accelerated windowless transparent flash player activex control to a texture. Something that is usually not possible, but which I hope to achieve with DirectComposition.

Crestfallen answered 1/7, 2013 at 5:58 Comment(5)
From MSDN "DirectComposition does not draw bitmaps, it only manipulates bitmaps that are already drawn." Does this cause a problem? As far as I know, it only composes directly to an HWND.Codeclination
Could I create a HWND from a SwapChain and then use the framebuffer?Crestfallen
Anything is worth a try - but the fact that you can only create an HWND target seems to imply that this is embedded in the OS quite deeply. I honestly don't know but I strongly suspect that a solution - if possible - will be at best a bit of a hack.Codeclination
A hack is fine, as long as it works.Crestfallen
+1 for the hacking spirit ;-) Happy to help further if you get some kind of code that shows promise.Codeclination
R
4

It's unlikely that this is possible, to quote MSDN (emphasis mine)

DirectComposition does not offer any rasterization services. An application must use some other software-based or hardware-accelerated rasterization library such as Direct2D or Direct3D to populate the bitmaps that are to be composed. After composing, DirectComposition passes composed bitmap content to Desktop Window Manager (DWM) for rendering to the screen.

As far as I know there are only official APIs to share your offscreen surfaces with DWM, but no API allowing you to get read-access to a DWM surface.

What DWM does allow you is redirecting HWND surfaces, so you can display the surfaces of other HWNDs on your window. This can be done either through DirectComposition (via CreateSurfaceFromHwnd) or the DWM API (via DwmRegisterThumbnail). For an example of the latter look here.

If you want to go the "hacking route" as indicated in your comment, there are undocumented APIs which look like they can give you access to the DWM surfaces, in particular DwmpDxGetWindowSharedSurface sounds promising. Someone else already did some reverse engineering and figured out the signature, but couldn't get it to work (texture works but renders black). This guy seems to have had more luck and was able to render window textures in 3d. I don't understand his language but you seem to have to use DwmpDxUpdateWindowSharedSurface (also undocumented).

You should be aware however that using undocumented functions is not a good idea, Microsoft can change them anytime (even in service pack releases) or remove them completely, since they are only used by Microsoft themselves they have no reason to maintain compatibility. Also there is a good chance that you are going to use them wrong (e.g. you might be missing necessary synchronization and cause random crashes, or worse).

However since the functionality is actually available there is hope that Microsoft may actually open it for puplic use in some future version of Windows.

Reliquary answered 11/1, 2014 at 21:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.