Sign in to follow this  
PumpkinPieman

Looking for a chain swapping example. [updated]

Recommended Posts

PumpkinPieman    382
It's exactly as the subject says, I'm looking for a simple chain swapping example. I've been looking around but I haven't found very much on it, has anyone done this kind of work that could lend me a hand? Thanks a bunch. [Edited by - PumpkinPieman on June 30, 2005 2:20:36 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
I'm not sure, but doesn't the DX SDK documentation give an example of chain swapping?

Share this post


Link to post
Share on other sites
PumpkinPieman    382
I'm not going to bother making another thread for this. I've continued to work with these swapchains and I'm at a roadblock right now. I'm really not sure what I'm doing wrong either. When I load up the first window it loads up the device and works fine, when I get to creating the swapchain and attempting to present it I get nothing. It rechecked all of the handles, the creations of objects and nothing was failing.

Here's the quick code I wrote to use swap chains.
cGraphicsSwapChain.h

class cGraphicsSwapChain
{
protected:
LPDIRECT3DSWAPCHAIN9 m_swapchain;
LPGRAPHICS m_graphics;
public:
cGraphicsSwapChain();
~cGraphicsSwapChain();

bool Create(LPWINDOW pWindow, LPGRAPHICS pGraphics);

bool SceneBegin(bool clear = true);
bool SceneEnd(void);
bool ScenePresent();

void Kill(void);
};



cGraphicsSwapChain.cpp

// *************************************************
// Class: cGraphicsChainSwap
// Info:
// *************************************************

cGraphicsSwapChain::cGraphicsSwapChain()
: m_swapchain(NULL)
, m_graphics(NULL)
{

};

cGraphicsSwapChain::~cGraphicsSwapChain()
{
Kill();
};

bool cGraphicsSwapChain::Create(LPWINDOW pWindow, LPGRAPHICS pGraphics)
{
if((pWindow == NULL) || (pWindow->IsInit() == false))
return false;

if(((m_graphics = pGraphics) == NULL) || (pGraphics->GetDevice() == NULL))
return false;

return (m_swapchain = m_graphics->CreateSwapChain(pWindow)) != NULL;
};

bool cGraphicsSwapChain::SceneBegin(bool clear)
{
assert(m_graphics != NULL);
assert(m_swapchain != NULL);

LPDIRECT3DSURFACE9 pBack = NULL;
m_swapchain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &pBack);

m_graphics->GetDevice()->SetRenderTarget(0, pBack);

return m_graphics->SceneBegin(clear);
};

bool cGraphicsSwapChain::SceneEnd(void)
{
assert(m_graphics != NULL);
return m_graphics->SceneEnd();
};

bool cGraphicsSwapChain::ScenePresent()
{
LPDIRECT3DSURFACE9 pBack = NULL;
assert(m_graphics != NULL);

bool ret = SUCCEEDED(m_swapchain->Present(NULL, NULL, NULL, NULL, 0));

m_graphics->GetDevice()->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pBack);
m_graphics->GetDevice()->SetRenderTarget(0, pBack);

return ret;
};

void cGraphicsSwapChain::Kill(void)
{
releaseCOM(m_swapchain);
m_graphics = NULL;
};




Here is the swapchain creation code in my graphics class

LPDIRECT3DSWAPCHAIN9 cGraphics::CreateSwapChain(LPWINDOW pWindow)
{
LPDIRECT3DSWAPCHAIN9 lpSwap;
D3DPRESENT_PARAMETERS d3dpp;
D3DDISPLAYMODE d3ddm;

/* ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS));

d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;

m_d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT , &d3ddm);

d3dpp.BackBufferFormat = d3ddm.Format;
d3dpp.hDeviceWindow = pWindow->GetHWND();
*/


m_d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm);

ZeroMemory(&d3dpp,sizeof(d3dpp));

d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = pWindow->GetHWND();
d3dpp.BackBufferCount = 1;
d3dpp.Windowed = true;
d3dpp.BackBufferFormat = d3ddm.Format;
d3dpp.BackBufferWidth = pWindow->GetWidth();
d3dpp.BackBufferHeight = pWindow->GetHeight();

if(m_zbuffer == true){
d3dpp.EnableAutoDepthStencil = true;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
}

bool ret = SUCCEEDED(m_device->CreateAdditionalSwapChain(&d3dpp, &lpSwap));
return lpSwap;
};



To set it up I use

cWindow cWnd;
CD3DAniWin* m_aniwindow;
RECT d3dwindow;

CWnd* d3dcwnd = GetDlgItem(IDC_FRAMEWIN);
HWND d3dhwnd = d3dcwnd->GetSafeHwnd();
d3dcwnd->GetClientRect(&d3dwindow);

cWnd.Init(d3dhwnd, d3dwindow.right, d3dwindow.bottom);
m_texviewer.Create(&cWnd, &m_aniwindow->d3dgraphics);

if(m_texviewer.SceneBegin(true)){

m_texviewer.SceneEnd();
}
m_texviewer.ScenePresent();


All three functions

m_texviewer.SceneBegin();
m_texviewer.SceneEnd();
m_texviewer.ScenePresent();

return true but don't render a blank screen.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this