Jump to content
  • Advertisement
Sign in to follow this  

creating multiple offscreen surfaces

This topic is 3032 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

I'd like to create multiple offscreen surfaces so that I could update 1 surface while the other is being pageflipped... and then pageflip the first while I update the second. I tried creating 2 IDirect3DSurfaces, but I got unpredictable results as I have a primary process updating frames (for stereo 3D video) while the DirectX process pageflips. Is this possible? It's not a classic Chain Swap but more of an either/or swap. If Surface2 is ready for display, then present it until Surface1 is ready for display, at which time present Surface1 until Surface2 is ready for display...

STEREO3D_Direct3DDevice9->CreateOffscreenPlainSurface(STEREO3D_Width*2, STEREO3D_Height+1, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &STEREO3D_ImageSourceSurface1, NULL);

STEREO3D_Direct3DDevice9->CreateOffscreenPlainSurface(STEREO3D_Width*2, STEREO3D_Height+1, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &STEREO3D_ImageSourceSurface2, NULL);

D3DLOCKED_RECT LockedRect1, LockedRect2;

STEREO3D_ImageSourceSurface1->LockRect(&LockedRect1, NULL, 0);
STEREO3D_ImageSourceSurface2->LockRect(&LockedRect2, NULL, 0);

LPNVSTEREOIMAGEHEADER pStereoImageHeader1 = (LPNVSTEREOIMAGEHEADER)(((unsigned char *) LockedRect1.pBits) + (LockedRect1.Pitch * (STEREO3D_Height)));

LPNVSTEREOIMAGEHEADER pStereoImageHeader2 = (LPNVSTEREOIMAGEHEADER)(((unsigned char *) LockedRect2.pBits) + (LockedRect2.Pitch * (STEREO3D_Height)));

pStereoImageHeader1->dwSignature = NVSTEREO_IMAGE_SIGNATURE;
pStereoImageHeader2->dwSignature = NVSTEREO_IMAGE_SIGNATURE;
pStereoImageHeader1->dwBPP = 32;
pStereoImageHeader2->dwBPP = 32;
pStereoImageHeader1->dwWidth = STEREO3D_Width*2;
pStereoImageHeader2->dwWidth = STEREO3D_Width*2;
pStereoImageHeader1->dwHeight = STEREO3D_Height;
pStereoImageHeader2->dwHeight = STEREO3D_Height;


RECT destRect;
destRect.left = 0;
destRect.top = 0;
destRect.right = STEREO3D_Width;
destRect.bottom = STEREO3D_Height;

MSG ThisMessage;

while (PeekMessage(&ThisMessage, NULL, 0, 0, PM_REMOVE))
DispatchMessage (&ThisMessage);

STEREO3D_Direct3DDevice9->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &STEREO3D_BackBufferSurface);

if (STEREO3D_PresentPair1)
STEREO3D_Direct3DDevice9->StretchRect(STEREO3D_ImageSourceSurface1, NULL, STEREO3D_BackBufferSurface, &destRect, D3DTEXF_NONE);
STEREO3D_Direct3DDevice9->StretchRect(STEREO3D_ImageSourceSurface2, NULL, STEREO3D_BackBufferSurface, &destRect, D3DTEXF_NONE);


STEREO3D_Direct3DDevice9->Present(NULL, NULL, NULL, NULL);
while (ThisMessage.wParam != VK_ESCAPE);

Share this post

Link to post
Share on other sites
From your source code, why don't you use Swapchain?

A swap chain is a series of virtual framebuffers utilized by the graphics card and graphics API for frame rate stabilization and several other functions. The swap chain usually exists in graphics memory, but it can exist in system memory as well. The non-utilization of a swap chain will result in stuttering rendering, but its existence and utilization are required by many graphics APIs. A swap chain with two buffers is a double buffer, and one with three is a triple buffer.

In every swap chain there are at least two buffers. One is front buffer or screen buffer which contains the contents you see on the screen. 1 or more called back buffer which can be used to render new frame(s) while a frame is presented/displayed to the screen.


If you insist to create some surfaces then present them to the screen you need to create a Render target.

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!