I have this function that initializes my 3d that gets called in the WM_CREATE event:
ID3D10Device *Device = NULL;
IDXGISwapChain *SwapChain = NULL;
ID3D10RenderTargetView *RenderTargetView = NULL;
HRESULT InitDevice(HWND hwnd)
{
HRESULT hr; RECT rc;
GetClientRect(hwnd, &rc);
DXGI_SWAP_CHAIN_DESC sd;
ZeroMemory(&sd, sizeof(sd));
sd.BufferCount = 1;
sd.BufferDesc.Width = (rc.right - rc.left);
sd.BufferDesc.Height = (rc.bottom - rc.top);
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
sd.BufferDesc.RefreshRate.Numerator = 60;
sd.BufferDesc.RefreshRate.Denominator = 1;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.OutputWindow = hwnd;
sd.SampleDesc.Count = 1;
sd.SampleDesc.Quality = 0;
sd.Windowed = TRUE;
hr = D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, D3D10_CREATE_DEVICE_DEBUG,
D3D10_SDK_VERSION, &sd, &SwapChain, &Device);
if(FAILED(hr)) return hr;
//create a render target view
ID3D10Texture2D *buffer;
hr = SwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)&buffer);
if(FAILED(hr)) return hr;
hr = Device->CreateRenderTargetView(buffer, NULL, &RenderTargetView);
buffer->Release();
if(FAILED(hr)) return hr;
Device->OMSetRenderTargets(1, &RenderTargetView, NULL);
//create the viewport
D3D10_VIEWPORT vp;
vp.Width = (rc.right - rc.left);
vp.Height = (rc.bottom - rc.top);
vp.MinDepth = 0.0f;
vp.MaxDepth = 1.0f;
vp.TopLeftX = 0;
vp.TopLeftY = 0;
Device->RSSetViewports(1, &vp);
return S_OK;
}
My question is: What happens in the WM_SIZE event? Do I have to release the devices and call this function again with the new width and height of the window? Do I have to just recreate the viewport (but then the backbuffer size would be wrong right?).