• 13
• 18
• 19
• 27
• 9

# VMR9 Rendering to a texture

This topic is 3899 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Just trying to get my head around VMR9... What I'm trying to do is - based on the VMR9Allocator sample - render each frame of video to a texture. Then I want to use the texture each time round my render loop to paint one (or more) sprites. This should result in video rendered in an existing 3D scene within my engine. Inside my allocator class (derived from IVMRSurfaceAllocator9 and IVMRImagePresenter9) I'm creating a texture on initialisation. When PresentImage is called I'm then using StretchRect to copy the rendered frame to this texture. (This all happens - I presume - in a separate thread, so I use the CAutoLock utility to make sure that there are no simultaneous access attempts on the texture.) Outside of this thread my main render loop is running. I am assuming that I can use the texture created in the allocator class then to paint onto sprites within my scene - with suitable calls on CAutoLock as before. Can anyone confirm that this is a rational approach? I've got a white square only at the moment which implies that I'm not setting up or using the textures correctly - or that this is simply not the way to do it! Hope that's clear - I'd be very grateful for any help.

##### Share on other sites
I've ran into this kind of problem myself.There was one thread about this problem awhile ago,can't seem to find it though.Anyway,the main problem is that the drawing runs on one thread and the DirectShow filters on another, the threads being asynchronous. DirectShow switches renderTargets (to the target surface) while the main part of the application is still drawing to the backbuffer effectively causing the drawing part of the application to render parts on the video surface and not on the backbuffer.
Use this to avoid the rendertarget switching :
hr = pVmr->QueryInterface(IID_IVMRMixerControl9, (void**)&pMix);if( SUCCEEDED(hr)) {    DWORD dwPrefs=0;    hr = pMix->GetMixingPrefs(&dwPrefs);    if (SUCCEEDED(hr))    {	dwPrefs &= ~MixerPref9_RenderTargetMask;	dwPrefs |= MixerPref9_RenderTargetYUV;		        hr = pMix->SetMixingPrefs(dwPrefs);    }    pMix->Release();}

This switches to YUV mode that is hardware accelerated and needs no rendertarget switching.Hope this helps.

##### Share on other sites
Many thanks for your help - I'll give that a go.