mardi 27 mai 2014

winapi - D3D Mobile : tampon arrière-> GetDC retourne toujours D3DMERR_INVALIDCALL - Stack Overflow


As the title indicates, I couldn't get a valid handle to the back buffer's DC using GetDC(). I've gone through the MSDN page for IDirect3DMobileSurface::GetDC several times now, trying to see whether I've missed something but could not find anything wrong with my approach.


I construct the D3DM device in the following manner:


    // .. some code
tD3DMPP.Windowed = TRUE;
tD3DMPP.BackBufferCount = 1;
tD3DMPP.BackBufferWidth = r.right - r.left;
tD3DMPP.BackBufferHeight = r.bottom - r.top - dwTitleBarHeight;//(UINT)tMode.Height;
tD3DMPP.BackBufferFormat = tBackBufferFormat; // D3DMFMT_R5G6B5
tD3DMPP.SwapEffect = D3DMSWAPEFFECT_DISCARD;
tD3DMPP.EnableAutoDepthStencil = FALSE;
tD3DMPP.Flags = D3DMPRESENTFLAG_LOCKABLE_BACKBUFFER;

// .. some code

if (g_tCaps.SurfaceCaps & D3DMSURFCAPS_VIDVERTEXBUFFER)
{
t_VBPool = D3DMPOOL_VIDEOMEM;
}

HRESULT res = g_pD3Dm->CreateDevice(D3DMADAPTER_DEFAULT,
D3DMDEVTYPE_DEFAULT,
hWnd,
NULL,
&tD3DMPP, &g_pD3DmDevice);

This produces a valid device which I use to render my scene. Here's the code that I use to get the back buffer's DC:


    if (NULL == p_BackBuffer)
{
g_pD3DmDevice->GetBackBuffer(0, D3DMBACKBUFFER_TYPE_MONO, &p_BackBuffer);
}

DWORD dwLastError = 0;
if (D3DMERR_INVALIDCALL == p_BackBuffer->GetDC(&_hdc))
{
dwLastError = GetLastError(); // gives last error as 0
//report error
p_BackBuffer->ReleaseDC(_hdc);
p_BackBuffer->Release();
return;
}

HGDIOBJ hOldFont = SelectObject (_hdc, g_hFont);
SetTextColor(_hdc, RGB(255, 255, 255));

ExtTextOutW(_hdc, 50,50, 0, NULL, _T("Test"), 4, NULL);
p_BackBuffer->ReleaseDC(_hdc);
p_BackBuffer->Release();

As shown in the code, the method fails in GetDC but gives the last error value as 0. I'd appreciate it if someone could help me to figure out what's wrong with my code.



As the title indicates, I couldn't get a valid handle to the back buffer's DC using GetDC(). I've gone through the MSDN page for IDirect3DMobileSurface::GetDC several times now, trying to see whether I've missed something but could not find anything wrong with my approach.


I construct the D3DM device in the following manner:


    // .. some code
tD3DMPP.Windowed = TRUE;
tD3DMPP.BackBufferCount = 1;
tD3DMPP.BackBufferWidth = r.right - r.left;
tD3DMPP.BackBufferHeight = r.bottom - r.top - dwTitleBarHeight;//(UINT)tMode.Height;
tD3DMPP.BackBufferFormat = tBackBufferFormat; // D3DMFMT_R5G6B5
tD3DMPP.SwapEffect = D3DMSWAPEFFECT_DISCARD;
tD3DMPP.EnableAutoDepthStencil = FALSE;
tD3DMPP.Flags = D3DMPRESENTFLAG_LOCKABLE_BACKBUFFER;

// .. some code

if (g_tCaps.SurfaceCaps & D3DMSURFCAPS_VIDVERTEXBUFFER)
{
t_VBPool = D3DMPOOL_VIDEOMEM;
}

HRESULT res = g_pD3Dm->CreateDevice(D3DMADAPTER_DEFAULT,
D3DMDEVTYPE_DEFAULT,
hWnd,
NULL,
&tD3DMPP, &g_pD3DmDevice);

This produces a valid device which I use to render my scene. Here's the code that I use to get the back buffer's DC:


    if (NULL == p_BackBuffer)
{
g_pD3DmDevice->GetBackBuffer(0, D3DMBACKBUFFER_TYPE_MONO, &p_BackBuffer);
}

DWORD dwLastError = 0;
if (D3DMERR_INVALIDCALL == p_BackBuffer->GetDC(&_hdc))
{
dwLastError = GetLastError(); // gives last error as 0
//report error
p_BackBuffer->ReleaseDC(_hdc);
p_BackBuffer->Release();
return;
}

HGDIOBJ hOldFont = SelectObject (_hdc, g_hFont);
SetTextColor(_hdc, RGB(255, 255, 255));

ExtTextOutW(_hdc, 50,50, 0, NULL, _T("Test"), 4, NULL);
p_BackBuffer->ReleaseDC(_hdc);
p_BackBuffer->Release();

As shown in the code, the method fails in GetDC but gives the last error value as 0. I'd appreciate it if someone could help me to figure out what's wrong with my code.


0 commentaires:

Enregistrer un commentaire