Move the code related to creating and resetting offscreen texture resources to its own method.

TRAC #21929 Signed-off-by: Nicolas Capens Signed-off-by: Shannon Woods Author: Jamie Madill git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1859 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 211fa2ed
...@@ -136,7 +136,7 @@ void SwapChain11::release() ...@@ -136,7 +136,7 @@ void SwapChain11::release()
} }
} }
EGLint SwapChain11::reset(int backbufferWidth, int backbufferHeight, EGLint swapInterval) EGLint SwapChain11::resetOffscreenTexture(int backbufferWidth, int backbufferHeight)
{ {
ID3D11Device *device = mRenderer->getDevice(); ID3D11Device *device = mRenderer->getDevice();
...@@ -145,26 +145,6 @@ EGLint SwapChain11::reset(int backbufferWidth, int backbufferHeight, EGLint swap ...@@ -145,26 +145,6 @@ EGLint SwapChain11::reset(int backbufferWidth, int backbufferHeight, EGLint swap
return EGL_BAD_ACCESS; return EGL_BAD_ACCESS;
} }
// Release specific resources to free up memory for the new render target, while the
// old render target still exists for the purpose of preserving its contents.
if (mSwapChain)
{
mSwapChain->Release();
mSwapChain = NULL;
}
if (mBackBufferTexture)
{
mBackBufferTexture->Release();
mBackBufferTexture = NULL;
}
if (mBackBufferRTView)
{
mBackBufferRTView->Release();
mBackBufferRTView = NULL;
}
if (mOffscreenTexture) if (mOffscreenTexture)
{ {
mOffscreenTexture->Release(); mOffscreenTexture->Release();
...@@ -195,13 +175,6 @@ EGLint SwapChain11::reset(int backbufferWidth, int backbufferHeight, EGLint swap ...@@ -195,13 +175,6 @@ EGLint SwapChain11::reset(int backbufferWidth, int backbufferHeight, EGLint swap
mDepthStencilDSView = NULL; mDepthStencilDSView = NULL;
} }
mSwapInterval = static_cast<unsigned int>(swapInterval);
if (mSwapInterval > 4)
{
// IDXGISwapChain::Present documentation states that valid sync intervals are in the [0,4] range
return EGL_BAD_PARAMETER;
}
// If the app passed in a share handle, open the resource // If the app passed in a share handle, open the resource
// See EGL_ANGLE_d3d_share_handle_client_buffer // See EGL_ANGLE_d3d_share_handle_client_buffer
if (mAppCreatedShareHandle) if (mAppCreatedShareHandle)
...@@ -310,6 +283,85 @@ EGLint SwapChain11::reset(int backbufferWidth, int backbufferHeight, EGLint swap ...@@ -310,6 +283,85 @@ EGLint SwapChain11::reset(int backbufferWidth, int backbufferHeight, EGLint swap
ASSERT(SUCCEEDED(result)); ASSERT(SUCCEEDED(result));
d3d11::SetDebugName(mOffscreenSRView, "Offscreen shader resource"); d3d11::SetDebugName(mOffscreenSRView, "Offscreen shader resource");
if (mDepthBufferFormat != GL_NONE)
{
D3D11_TEXTURE2D_DESC depthStencilDesc = {0};
depthStencilDesc.Width = backbufferWidth;
depthStencilDesc.Height = backbufferHeight;
depthStencilDesc.Format = gl_d3d11::ConvertRenderbufferFormat(mDepthBufferFormat);
depthStencilDesc.MipLevels = 1;
depthStencilDesc.ArraySize = 1;
depthStencilDesc.SampleDesc.Count = 1;
depthStencilDesc.SampleDesc.Quality = 0;
depthStencilDesc.Usage = D3D11_USAGE_DEFAULT;
depthStencilDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
depthStencilDesc.CPUAccessFlags = 0;
depthStencilDesc.MiscFlags = 0;
result = device->CreateTexture2D(&depthStencilDesc, NULL, &mDepthStencilTexture);
if (FAILED(result))
{
ERR("Could not create depthstencil surface for new swap chain: 0x%08X", result);
release();
if (d3d11::isDeviceLostError(result))
{
return EGL_CONTEXT_LOST;
}
else
{
return EGL_BAD_ALLOC;
}
}
d3d11::SetDebugName(mDepthStencilTexture, "Depth stencil texture");
result = device->CreateDepthStencilView(mDepthStencilTexture, NULL, &mDepthStencilDSView);
ASSERT(SUCCEEDED(result));
d3d11::SetDebugName(mDepthStencilDSView, "Depth stencil view");
}
mWidth = backbufferWidth;
mHeight = backbufferHeight;
return EGL_SUCCESS;
}
EGLint SwapChain11::reset(int backbufferWidth, int backbufferHeight, EGLint swapInterval)
{
ID3D11Device *device = mRenderer->getDevice();
if (device == NULL)
{
return EGL_BAD_ACCESS;
}
// Release specific resources to free up memory for the new render target, while the
// old render target still exists for the purpose of preserving its contents.
if (mSwapChain)
{
mSwapChain->Release();
mSwapChain = NULL;
}
if (mBackBufferTexture)
{
mBackBufferTexture->Release();
mBackBufferTexture = NULL;
}
if (mBackBufferRTView)
{
mBackBufferRTView->Release();
mBackBufferRTView = NULL;
}
mSwapInterval = static_cast<unsigned int>(swapInterval);
if (mSwapInterval > 4)
{
// IDXGISwapChain::Present documentation states that valid sync intervals are in the [0,4] range
return EGL_BAD_PARAMETER;
}
if (mWindow) if (mWindow)
{ {
// We cannot create a swap chain for an HWND that is owned by a different process // We cannot create a swap chain for an HWND that is owned by a different process
...@@ -342,7 +394,7 @@ EGLint SwapChain11::reset(int backbufferWidth, int backbufferHeight, EGLint swap ...@@ -342,7 +394,7 @@ EGLint SwapChain11::reset(int backbufferWidth, int backbufferHeight, EGLint swap
swapChainDesc.SampleDesc.Quality = 0; swapChainDesc.SampleDesc.Quality = 0;
swapChainDesc.Windowed = TRUE; swapChainDesc.Windowed = TRUE;
result = factory->CreateSwapChain(device, &swapChainDesc, &mSwapChain); HRESULT result = factory->CreateSwapChain(device, &swapChainDesc, &mSwapChain);
if (FAILED(result)) if (FAILED(result))
{ {
...@@ -368,43 +420,6 @@ EGLint SwapChain11::reset(int backbufferWidth, int backbufferHeight, EGLint swap ...@@ -368,43 +420,6 @@ EGLint SwapChain11::reset(int backbufferWidth, int backbufferHeight, EGLint swap
d3d11::SetDebugName(mBackBufferRTView, "Back buffer render target"); d3d11::SetDebugName(mBackBufferRTView, "Back buffer render target");
} }
if (mDepthBufferFormat != GL_NONE)
{
D3D11_TEXTURE2D_DESC depthStencilDesc = {0};
depthStencilDesc.Width = backbufferWidth;
depthStencilDesc.Height = backbufferHeight;
depthStencilDesc.Format = gl_d3d11::ConvertRenderbufferFormat(mDepthBufferFormat);
depthStencilDesc.MipLevels = 1;
depthStencilDesc.ArraySize = 1;
depthStencilDesc.SampleDesc.Count = 1;
depthStencilDesc.SampleDesc.Quality = 0;
depthStencilDesc.Usage = D3D11_USAGE_DEFAULT;
depthStencilDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
depthStencilDesc.CPUAccessFlags = 0;
depthStencilDesc.MiscFlags = 0;
result = device->CreateTexture2D(&depthStencilDesc, NULL, &mDepthStencilTexture);
if (FAILED(result))
{
ERR("Could not create depthstencil surface for new swap chain: 0x%08X", result);
release();
if (d3d11::isDeviceLostError(result))
{
return EGL_CONTEXT_LOST;
}
else
{
return EGL_BAD_ALLOC;
}
}
d3d11::SetDebugName(mDepthStencilTexture, "Depth stencil texture");
result = device->CreateDepthStencilView(mDepthStencilTexture, NULL, &mDepthStencilDSView);
ASSERT(SUCCEEDED(result));
d3d11::SetDebugName(mDepthStencilDSView, "Depth stencil view");
}
// If we are resizing the swap chain, we don't wish to recreate all the static resources // If we are resizing the swap chain, we don't wish to recreate all the static resources
if (!mPassThroughResourcesInit) if (!mPassThroughResourcesInit)
{ {
...@@ -412,10 +427,7 @@ EGLint SwapChain11::reset(int backbufferWidth, int backbufferHeight, EGLint swap ...@@ -412,10 +427,7 @@ EGLint SwapChain11::reset(int backbufferWidth, int backbufferHeight, EGLint swap
initPassThroughResources(); initPassThroughResources();
} }
mWidth = backbufferWidth; return resetOffscreenTexture(backbufferWidth, backbufferHeight);
mHeight = backbufferHeight;
return EGL_SUCCESS;
} }
void SwapChain11::initPassThroughResources() void SwapChain11::initPassThroughResources()
......
...@@ -44,6 +44,7 @@ class SwapChain11 : public SwapChain ...@@ -44,6 +44,7 @@ class SwapChain11 : public SwapChain
void release(); void release();
void initPassThroughResources(); void initPassThroughResources();
EGLint resetOffscreenTexture(int backbufferWidth, int backbufferHeight);
Renderer11 *mRenderer; Renderer11 *mRenderer;
EGLint mHeight; EGLint mHeight;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment