Jump to content
  • Advertisement
Sign in to follow this  
blairhartley

VMR9 Rendering to a texture

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
You might like to also consider removing any call to SetNumberOfStreams, otherwise you turn on the mixer and that can cause issues running the allocator on a separate thread.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!