shannon.woods@transgaming.com | bdf2d80 | 2013-02-28 23:16:20 +0000 | [diff] [blame] | 1 | #include "precompiled.h" |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 2 | // |
daniel@transgaming.com | ed36abd | 2013-01-11 21:15:58 +0000 | [diff] [blame] | 3 | // Copyright (c) 2012-2013 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 4 | // Use of this source code is governed by a BSD-style license that can be |
| 5 | // found in the LICENSE file. |
| 6 | // |
| 7 | |
| 8 | // SwapChain11.cpp: Implements a back-end specific class for the D3D11 swap chain. |
| 9 | |
| 10 | #include "libGLESv2/renderer/SwapChain11.h" |
| 11 | |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 12 | #include "libGLESv2/renderer/renderer11_utils.h" |
| 13 | #include "libGLESv2/renderer/Renderer11.h" |
daniel@transgaming.com | 8dc8e27 | 2013-01-11 04:10:45 +0000 | [diff] [blame] | 14 | #include "libGLESv2/renderer/shaders/compiled/passthrough11vs.h" |
shannon.woods@transgaming.com | 2570c34 | 2013-01-25 21:50:22 +0000 | [diff] [blame] | 15 | #include "libGLESv2/renderer/shaders/compiled/passthroughrgba11ps.h" |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 16 | |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 17 | namespace rx |
| 18 | { |
| 19 | |
| 20 | SwapChain11::SwapChain11(Renderer11 *renderer, HWND window, HANDLE shareHandle, |
| 21 | GLenum backBufferFormat, GLenum depthBufferFormat) |
| 22 | : mRenderer(renderer), SwapChain(window, shareHandle, backBufferFormat, depthBufferFormat) |
| 23 | { |
| 24 | mSwapChain = NULL; |
daniel@transgaming.com | c8c70ad | 2012-11-28 21:04:37 +0000 | [diff] [blame] | 25 | mBackBufferTexture = NULL; |
| 26 | mBackBufferRTView = NULL; |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 27 | mOffscreenTexture = NULL; |
daniel@transgaming.com | c8c70ad | 2012-11-28 21:04:37 +0000 | [diff] [blame] | 28 | mOffscreenRTView = NULL; |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 29 | mOffscreenSRView = NULL; |
daniel@transgaming.com | c8c70ad | 2012-11-28 21:04:37 +0000 | [diff] [blame] | 30 | mDepthStencilTexture = NULL; |
| 31 | mDepthStencilDSView = NULL; |
daniel@transgaming.com | f06e539 | 2013-01-11 21:15:50 +0000 | [diff] [blame] | 32 | mQuadVB = NULL; |
| 33 | mPassThroughSampler = NULL; |
| 34 | mPassThroughIL = NULL; |
| 35 | mPassThroughVS = NULL; |
| 36 | mPassThroughPS = NULL; |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 37 | mWidth = -1; |
| 38 | mHeight = -1; |
shannon.woods@transgaming.com | ad74a4b | 2013-02-28 23:04:09 +0000 | [diff] [blame] | 39 | mSwapInterval = 0; |
shannon.woods@transgaming.com | c60c521 | 2013-01-25 21:54:01 +0000 | [diff] [blame] | 40 | mAppCreatedShareHandle = mShareHandle != NULL; |
shannon.woods@transgaming.com | 211fa2e | 2013-02-28 23:05:23 +0000 | [diff] [blame] | 41 | mPassThroughResourcesInit = false; |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | SwapChain11::~SwapChain11() |
| 45 | { |
| 46 | release(); |
| 47 | } |
| 48 | |
| 49 | void SwapChain11::release() |
| 50 | { |
| 51 | if (mSwapChain) |
| 52 | { |
| 53 | mSwapChain->Release(); |
| 54 | mSwapChain = NULL; |
| 55 | } |
| 56 | |
daniel@transgaming.com | c8c70ad | 2012-11-28 21:04:37 +0000 | [diff] [blame] | 57 | if (mBackBufferTexture) |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 58 | { |
daniel@transgaming.com | c8c70ad | 2012-11-28 21:04:37 +0000 | [diff] [blame] | 59 | mBackBufferTexture->Release(); |
| 60 | mBackBufferTexture = NULL; |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 61 | } |
| 62 | |
daniel@transgaming.com | c8c70ad | 2012-11-28 21:04:37 +0000 | [diff] [blame] | 63 | if (mBackBufferRTView) |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 64 | { |
daniel@transgaming.com | c8c70ad | 2012-11-28 21:04:37 +0000 | [diff] [blame] | 65 | mBackBufferRTView->Release(); |
| 66 | mBackBufferRTView = NULL; |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | if (mOffscreenTexture) |
| 70 | { |
| 71 | mOffscreenTexture->Release(); |
| 72 | mOffscreenTexture = NULL; |
| 73 | } |
| 74 | |
daniel@transgaming.com | c8c70ad | 2012-11-28 21:04:37 +0000 | [diff] [blame] | 75 | if (mOffscreenRTView) |
| 76 | { |
| 77 | mOffscreenRTView->Release(); |
| 78 | mOffscreenRTView = NULL; |
| 79 | } |
| 80 | |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 81 | if (mOffscreenSRView) |
| 82 | { |
| 83 | mOffscreenSRView->Release(); |
| 84 | mOffscreenSRView = NULL; |
| 85 | } |
| 86 | |
daniel@transgaming.com | c8c70ad | 2012-11-28 21:04:37 +0000 | [diff] [blame] | 87 | if (mDepthStencilTexture) |
| 88 | { |
| 89 | mDepthStencilTexture->Release(); |
| 90 | mDepthStencilTexture = NULL; |
| 91 | } |
| 92 | |
| 93 | if (mDepthStencilDSView) |
| 94 | { |
| 95 | mDepthStencilDSView->Release(); |
| 96 | mDepthStencilDSView = NULL; |
| 97 | } |
| 98 | |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 99 | if (mQuadVB) |
| 100 | { |
| 101 | mQuadVB->Release(); |
| 102 | mQuadVB = NULL; |
| 103 | } |
| 104 | |
| 105 | if (mPassThroughSampler) |
| 106 | { |
| 107 | mPassThroughSampler->Release(); |
| 108 | mPassThroughSampler = NULL; |
| 109 | } |
| 110 | |
| 111 | if (mPassThroughIL) |
| 112 | { |
| 113 | mPassThroughIL->Release(); |
| 114 | mPassThroughIL = NULL; |
| 115 | } |
| 116 | |
| 117 | if (mPassThroughVS) |
| 118 | { |
| 119 | mPassThroughVS->Release(); |
| 120 | mPassThroughVS = NULL; |
| 121 | } |
| 122 | |
| 123 | if (mPassThroughPS) |
| 124 | { |
| 125 | mPassThroughPS->Release(); |
| 126 | mPassThroughPS = NULL; |
| 127 | } |
| 128 | |
shannon.woods@transgaming.com | c60c521 | 2013-01-25 21:54:01 +0000 | [diff] [blame] | 129 | if (!mAppCreatedShareHandle) |
| 130 | { |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 131 | mShareHandle = NULL; |
shannon.woods@transgaming.com | c60c521 | 2013-01-25 21:54:01 +0000 | [diff] [blame] | 132 | } |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 133 | } |
| 134 | |
shannon.woods@transgaming.com | 30f52c6 | 2013-02-28 23:05:34 +0000 | [diff] [blame] | 135 | void SwapChain11::releaseOffscreenTexture() |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 136 | { |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 137 | if (mOffscreenTexture) |
| 138 | { |
| 139 | mOffscreenTexture->Release(); |
| 140 | mOffscreenTexture = NULL; |
| 141 | } |
| 142 | |
shannon.woods@transgaming.com | 30f52c6 | 2013-02-28 23:05:34 +0000 | [diff] [blame] | 143 | if (mOffscreenRTView) |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 144 | { |
daniel@transgaming.com | c8c70ad | 2012-11-28 21:04:37 +0000 | [diff] [blame] | 145 | mOffscreenRTView->Release(); |
| 146 | mOffscreenRTView = NULL; |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 147 | } |
| 148 | |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 149 | if (mOffscreenSRView) |
| 150 | { |
| 151 | mOffscreenSRView->Release(); |
| 152 | mOffscreenSRView = NULL; |
| 153 | } |
| 154 | |
daniel@transgaming.com | c8c70ad | 2012-11-28 21:04:37 +0000 | [diff] [blame] | 155 | if (mDepthStencilTexture) |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 156 | { |
daniel@transgaming.com | c8c70ad | 2012-11-28 21:04:37 +0000 | [diff] [blame] | 157 | mDepthStencilTexture->Release(); |
| 158 | mDepthStencilTexture = NULL; |
| 159 | } |
| 160 | |
| 161 | if (mDepthStencilDSView) |
| 162 | { |
| 163 | mDepthStencilDSView->Release(); |
| 164 | mDepthStencilDSView = NULL; |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 165 | } |
shannon.woods@transgaming.com | 30f52c6 | 2013-02-28 23:05:34 +0000 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | EGLint SwapChain11::resetOffscreenTexture(int backbufferWidth, int backbufferHeight) |
| 169 | { |
| 170 | ID3D11Device *device = mRenderer->getDevice(); |
| 171 | |
| 172 | ASSERT(device != NULL); |
| 173 | |
| 174 | // D3D11 does not allow zero size textures |
| 175 | ASSERT(backbufferWidth >= 1); |
| 176 | ASSERT(backbufferHeight >= 1); |
| 177 | |
| 178 | // Preserve the render target content |
| 179 | ID3D11Texture2D *previousOffscreenTexture = mOffscreenTexture; |
| 180 | if (previousOffscreenTexture) |
| 181 | { |
| 182 | previousOffscreenTexture->AddRef(); |
| 183 | } |
| 184 | const int previousWidth = mWidth; |
| 185 | const int previousHeight = mHeight; |
| 186 | |
| 187 | releaseOffscreenTexture(); |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 188 | |
shannon.woods@transgaming.com | c60c521 | 2013-01-25 21:54:01 +0000 | [diff] [blame] | 189 | // If the app passed in a share handle, open the resource |
| 190 | // See EGL_ANGLE_d3d_share_handle_client_buffer |
| 191 | if (mAppCreatedShareHandle) |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 192 | { |
shannon.woods@transgaming.com | c60c521 | 2013-01-25 21:54:01 +0000 | [diff] [blame] | 193 | ID3D11Resource *tempResource11; |
| 194 | HRESULT result = device->OpenSharedResource(mShareHandle, __uuidof(ID3D11Resource), (void**)&tempResource11); |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 195 | |
shannon.woods@transgaming.com | c60c521 | 2013-01-25 21:54:01 +0000 | [diff] [blame] | 196 | if (FAILED(result)) |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 197 | { |
shannon.woods@transgaming.com | c60c521 | 2013-01-25 21:54:01 +0000 | [diff] [blame] | 198 | ERR("Failed to open the swap chain pbuffer share handle: %08lX", result); |
| 199 | release(); |
| 200 | return EGL_BAD_PARAMETER; |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 201 | } |
shannon.woods@transgaming.com | c60c521 | 2013-01-25 21:54:01 +0000 | [diff] [blame] | 202 | |
| 203 | result = tempResource11->QueryInterface(__uuidof(ID3D11Texture2D), (void**)&mOffscreenTexture); |
| 204 | tempResource11->Release(); |
| 205 | |
| 206 | if (FAILED(result)) |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 207 | { |
shannon.woods@transgaming.com | c60c521 | 2013-01-25 21:54:01 +0000 | [diff] [blame] | 208 | ERR("Failed to query texture2d interface in pbuffer share handle: %08lX", result); |
| 209 | release(); |
| 210 | return EGL_BAD_PARAMETER; |
| 211 | } |
| 212 | |
| 213 | // Validate offscreen texture parameters |
| 214 | D3D11_TEXTURE2D_DESC offscreenTextureDesc = {0}; |
| 215 | mOffscreenTexture->GetDesc(&offscreenTextureDesc); |
| 216 | |
| 217 | if (offscreenTextureDesc.Width != (UINT)backbufferWidth |
| 218 | || offscreenTextureDesc.Height != (UINT)backbufferHeight |
| 219 | || offscreenTextureDesc.Format != gl_d3d11::ConvertRenderbufferFormat(mBackBufferFormat) |
| 220 | || offscreenTextureDesc.MipLevels != 1 |
| 221 | || offscreenTextureDesc.ArraySize != 1) |
| 222 | { |
| 223 | ERR("Invalid texture parameters in the shared offscreen texture pbuffer"); |
| 224 | release(); |
| 225 | return EGL_BAD_PARAMETER; |
| 226 | } |
| 227 | } |
| 228 | else |
| 229 | { |
| 230 | const bool useSharedResource = !mWindow && mRenderer->getShareHandleSupport(); |
| 231 | |
| 232 | D3D11_TEXTURE2D_DESC offscreenTextureDesc = {0}; |
| 233 | offscreenTextureDesc.Width = backbufferWidth; |
| 234 | offscreenTextureDesc.Height = backbufferHeight; |
| 235 | offscreenTextureDesc.Format = gl_d3d11::ConvertRenderbufferFormat(mBackBufferFormat); |
| 236 | offscreenTextureDesc.MipLevels = 1; |
| 237 | offscreenTextureDesc.ArraySize = 1; |
| 238 | offscreenTextureDesc.SampleDesc.Count = 1; |
| 239 | offscreenTextureDesc.SampleDesc.Quality = 0; |
| 240 | offscreenTextureDesc.Usage = D3D11_USAGE_DEFAULT; |
| 241 | offscreenTextureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE; |
| 242 | offscreenTextureDesc.CPUAccessFlags = 0; |
| 243 | offscreenTextureDesc.MiscFlags = useSharedResource ? D3D11_RESOURCE_MISC_SHARED : 0; |
| 244 | |
| 245 | HRESULT result = device->CreateTexture2D(&offscreenTextureDesc, NULL, &mOffscreenTexture); |
| 246 | |
| 247 | if (FAILED(result)) |
| 248 | { |
| 249 | ERR("Could not create offscreen texture: %08lX", result); |
| 250 | release(); |
| 251 | |
shannon.woods@transgaming.com | f5f5949 | 2013-02-28 23:04:40 +0000 | [diff] [blame] | 252 | if (d3d11::isDeviceLostError(result)) |
shannon.woods@transgaming.com | c60c521 | 2013-01-25 21:54:01 +0000 | [diff] [blame] | 253 | { |
| 254 | return EGL_CONTEXT_LOST; |
| 255 | } |
| 256 | else |
| 257 | { |
| 258 | return EGL_BAD_ALLOC; |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | d3d11::SetDebugName(mOffscreenTexture, "Offscreen texture"); |
| 263 | |
| 264 | // EGL_ANGLE_surface_d3d_texture_2d_share_handle requires that we store a share handle for the client |
| 265 | if (useSharedResource) |
| 266 | { |
| 267 | IDXGIResource *offscreenTextureResource = NULL; |
| 268 | result = mOffscreenTexture->QueryInterface(__uuidof(IDXGIResource), (void**)&offscreenTextureResource); |
| 269 | |
| 270 | // Fall back to no share handle on failure |
| 271 | if (FAILED(result)) |
| 272 | { |
| 273 | ERR("Could not query offscreen texture resource: %08lX", result); |
| 274 | } |
| 275 | else |
| 276 | { |
| 277 | result = offscreenTextureResource->GetSharedHandle(&mShareHandle); |
| 278 | |
| 279 | if (FAILED(result)) |
| 280 | { |
| 281 | mShareHandle = NULL; |
| 282 | ERR("Could not get offscreen texture shared handle: %08lX", result); |
| 283 | } |
| 284 | } |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 285 | } |
| 286 | } |
| 287 | |
shannon.woods@transgaming.com | c60c521 | 2013-01-25 21:54:01 +0000 | [diff] [blame] | 288 | HRESULT result = device->CreateRenderTargetView(mOffscreenTexture, NULL, &mOffscreenRTView); |
| 289 | |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 290 | ASSERT(SUCCEEDED(result)); |
daniel@transgaming.com | ad3d827 | 2013-01-11 04:11:14 +0000 | [diff] [blame] | 291 | d3d11::SetDebugName(mOffscreenRTView, "Offscreen render target"); |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 292 | |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 293 | result = device->CreateShaderResourceView(mOffscreenTexture, NULL, &mOffscreenSRView); |
| 294 | ASSERT(SUCCEEDED(result)); |
daniel@transgaming.com | ad3d827 | 2013-01-11 04:11:14 +0000 | [diff] [blame] | 295 | d3d11::SetDebugName(mOffscreenSRView, "Offscreen shader resource"); |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 296 | |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 297 | if (mDepthBufferFormat != GL_NONE) |
| 298 | { |
| 299 | D3D11_TEXTURE2D_DESC depthStencilDesc = {0}; |
| 300 | depthStencilDesc.Width = backbufferWidth; |
| 301 | depthStencilDesc.Height = backbufferHeight; |
| 302 | depthStencilDesc.Format = gl_d3d11::ConvertRenderbufferFormat(mDepthBufferFormat); |
| 303 | depthStencilDesc.MipLevels = 1; |
| 304 | depthStencilDesc.ArraySize = 1; |
| 305 | depthStencilDesc.SampleDesc.Count = 1; |
| 306 | depthStencilDesc.SampleDesc.Quality = 0; |
| 307 | depthStencilDesc.Usage = D3D11_USAGE_DEFAULT; |
| 308 | depthStencilDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL; |
| 309 | depthStencilDesc.CPUAccessFlags = 0; |
| 310 | depthStencilDesc.MiscFlags = 0; |
| 311 | |
daniel@transgaming.com | c8c70ad | 2012-11-28 21:04:37 +0000 | [diff] [blame] | 312 | result = device->CreateTexture2D(&depthStencilDesc, NULL, &mDepthStencilTexture); |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 313 | if (FAILED(result)) |
| 314 | { |
| 315 | ERR("Could not create depthstencil surface for new swap chain: 0x%08X", result); |
| 316 | release(); |
| 317 | |
shannon.woods@transgaming.com | f5f5949 | 2013-02-28 23:04:40 +0000 | [diff] [blame] | 318 | if (d3d11::isDeviceLostError(result)) |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 319 | { |
| 320 | return EGL_CONTEXT_LOST; |
| 321 | } |
| 322 | else |
| 323 | { |
| 324 | return EGL_BAD_ALLOC; |
| 325 | } |
| 326 | } |
daniel@transgaming.com | ad3d827 | 2013-01-11 04:11:14 +0000 | [diff] [blame] | 327 | d3d11::SetDebugName(mDepthStencilTexture, "Depth stencil texture"); |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 328 | |
daniel@transgaming.com | c8c70ad | 2012-11-28 21:04:37 +0000 | [diff] [blame] | 329 | result = device->CreateDepthStencilView(mDepthStencilTexture, NULL, &mDepthStencilDSView); |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 330 | ASSERT(SUCCEEDED(result)); |
daniel@transgaming.com | ad3d827 | 2013-01-11 04:11:14 +0000 | [diff] [blame] | 331 | d3d11::SetDebugName(mDepthStencilDSView, "Depth stencil view"); |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 332 | } |
| 333 | |
shannon.woods@transgaming.com | ae81383 | 2013-02-28 23:05:28 +0000 | [diff] [blame] | 334 | mWidth = backbufferWidth; |
| 335 | mHeight = backbufferHeight; |
| 336 | |
shannon.woods@transgaming.com | 30f52c6 | 2013-02-28 23:05:34 +0000 | [diff] [blame] | 337 | if (previousOffscreenTexture != NULL) |
| 338 | { |
| 339 | D3D11_BOX sourceBox = {0}; |
| 340 | sourceBox.left = 0; |
| 341 | sourceBox.right = std::min(previousWidth, mWidth); |
| 342 | sourceBox.top = std::max(previousHeight - mHeight, 0); |
| 343 | sourceBox.bottom = previousHeight; |
| 344 | sourceBox.front = 0; |
| 345 | sourceBox.back = 1; |
| 346 | |
| 347 | ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); |
| 348 | const int yoffset = std::max(mHeight - previousHeight, 0); |
| 349 | deviceContext->CopySubresourceRegion(mOffscreenTexture, 0, 0, yoffset, 0, previousOffscreenTexture, 0, &sourceBox); |
| 350 | |
| 351 | previousOffscreenTexture->Release(); |
| 352 | |
| 353 | if (mSwapChain) |
| 354 | { |
| 355 | swapRect(0, 0, mWidth, mHeight); |
| 356 | } |
| 357 | } |
| 358 | |
shannon.woods@transgaming.com | ae81383 | 2013-02-28 23:05:28 +0000 | [diff] [blame] | 359 | return EGL_SUCCESS; |
| 360 | } |
| 361 | |
shannon.woods@transgaming.com | c71ca75 | 2013-02-28 23:06:50 +0000 | [diff] [blame] | 362 | EGLint SwapChain11::resize(EGLint backbufferWidth, EGLint backbufferHeight) |
| 363 | { |
| 364 | ID3D11Device *device = mRenderer->getDevice(); |
| 365 | |
| 366 | if (device == NULL) |
| 367 | { |
| 368 | return EGL_BAD_ACCESS; |
| 369 | } |
| 370 | |
| 371 | // Can only call resize if we have already created our swap buffer and resources |
| 372 | ASSERT(mSwapChain && mBackBufferTexture && mBackBufferRTView); |
| 373 | |
| 374 | if (mBackBufferTexture) |
| 375 | { |
| 376 | mBackBufferTexture->Release(); |
| 377 | mBackBufferTexture = NULL; |
| 378 | } |
| 379 | |
| 380 | if (mBackBufferRTView) |
| 381 | { |
| 382 | mBackBufferRTView->Release(); |
| 383 | mBackBufferRTView = NULL; |
| 384 | } |
| 385 | |
| 386 | // Resize swap chain |
| 387 | DXGI_FORMAT backbufferDXGIFormat = gl_d3d11::ConvertRenderbufferFormat(mBackBufferFormat); |
| 388 | HRESULT result = mSwapChain->ResizeBuffers(2, backbufferWidth, backbufferHeight, backbufferDXGIFormat, 0); |
| 389 | |
| 390 | if (FAILED(result)) |
| 391 | { |
| 392 | ERR("Error resizing swap chain buffers: 0x%08X", result); |
| 393 | release(); |
| 394 | |
| 395 | if (d3d11::isDeviceLostError(result)) |
| 396 | { |
| 397 | return EGL_CONTEXT_LOST; |
| 398 | } |
| 399 | else |
| 400 | { |
| 401 | return EGL_BAD_ALLOC; |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | result = mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&mBackBufferTexture); |
| 406 | ASSERT(SUCCEEDED(result)); |
| 407 | if (SUCCEEDED(result)) |
| 408 | { |
| 409 | d3d11::SetDebugName(mBackBufferTexture, "Back buffer texture"); |
| 410 | } |
| 411 | |
| 412 | result = device->CreateRenderTargetView(mBackBufferTexture, NULL, &mBackBufferRTView); |
| 413 | ASSERT(SUCCEEDED(result)); |
| 414 | if (SUCCEEDED(result)) |
| 415 | { |
| 416 | d3d11::SetDebugName(mBackBufferRTView, "Back buffer render target"); |
| 417 | } |
| 418 | |
| 419 | return resetOffscreenTexture(backbufferWidth, backbufferHeight); |
| 420 | } |
| 421 | |
shannon.woods@transgaming.com | ae81383 | 2013-02-28 23:05:28 +0000 | [diff] [blame] | 422 | EGLint SwapChain11::reset(int backbufferWidth, int backbufferHeight, EGLint swapInterval) |
| 423 | { |
| 424 | ID3D11Device *device = mRenderer->getDevice(); |
| 425 | |
| 426 | if (device == NULL) |
| 427 | { |
| 428 | return EGL_BAD_ACCESS; |
| 429 | } |
| 430 | |
| 431 | // Release specific resources to free up memory for the new render target, while the |
| 432 | // old render target still exists for the purpose of preserving its contents. |
| 433 | if (mSwapChain) |
| 434 | { |
| 435 | mSwapChain->Release(); |
| 436 | mSwapChain = NULL; |
| 437 | } |
| 438 | |
| 439 | if (mBackBufferTexture) |
| 440 | { |
| 441 | mBackBufferTexture->Release(); |
| 442 | mBackBufferTexture = NULL; |
| 443 | } |
| 444 | |
| 445 | if (mBackBufferRTView) |
| 446 | { |
| 447 | mBackBufferRTView->Release(); |
| 448 | mBackBufferRTView = NULL; |
| 449 | } |
| 450 | |
| 451 | mSwapInterval = static_cast<unsigned int>(swapInterval); |
| 452 | if (mSwapInterval > 4) |
| 453 | { |
| 454 | // IDXGISwapChain::Present documentation states that valid sync intervals are in the [0,4] range |
| 455 | return EGL_BAD_PARAMETER; |
| 456 | } |
| 457 | |
shannon.woods@transgaming.com | 8c6d9df | 2013-02-28 23:08:57 +0000 | [diff] [blame] | 458 | // EGL allows creating a surface with 0x0 dimension, however, DXGI does not like 0x0 swapchains |
| 459 | if (backbufferWidth < 1 || backbufferHeight < 1) |
| 460 | { |
| 461 | releaseOffscreenTexture(); |
| 462 | return EGL_SUCCESS; |
| 463 | } |
| 464 | |
shannon.woods@transgaming.com | ae81383 | 2013-02-28 23:05:28 +0000 | [diff] [blame] | 465 | if (mWindow) |
| 466 | { |
| 467 | // We cannot create a swap chain for an HWND that is owned by a different process |
| 468 | DWORD currentProcessId = GetCurrentProcessId(); |
| 469 | DWORD wndProcessId; |
| 470 | GetWindowThreadProcessId(mWindow, &wndProcessId); |
| 471 | |
| 472 | if (currentProcessId != wndProcessId) |
| 473 | { |
| 474 | ERR("Could not create swap chain, window owned by different process"); |
| 475 | release(); |
| 476 | return EGL_BAD_NATIVE_WINDOW; |
| 477 | } |
| 478 | |
| 479 | IDXGIFactory *factory = mRenderer->getDxgiFactory(); |
| 480 | |
| 481 | DXGI_SWAP_CHAIN_DESC swapChainDesc = {0}; |
| 482 | swapChainDesc.BufferCount = 2; |
| 483 | swapChainDesc.BufferDesc.Format = gl_d3d11::ConvertRenderbufferFormat(mBackBufferFormat); |
| 484 | swapChainDesc.BufferDesc.Width = backbufferWidth; |
| 485 | swapChainDesc.BufferDesc.Height = backbufferHeight; |
| 486 | swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; |
| 487 | swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; |
| 488 | swapChainDesc.BufferDesc.RefreshRate.Numerator = 0; |
| 489 | swapChainDesc.BufferDesc.RefreshRate.Denominator = 1; |
| 490 | swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; |
| 491 | swapChainDesc.Flags = 0; |
| 492 | swapChainDesc.OutputWindow = mWindow; |
| 493 | swapChainDesc.SampleDesc.Count = 1; |
| 494 | swapChainDesc.SampleDesc.Quality = 0; |
| 495 | swapChainDesc.Windowed = TRUE; |
| 496 | |
| 497 | HRESULT result = factory->CreateSwapChain(device, &swapChainDesc, &mSwapChain); |
| 498 | |
| 499 | if (FAILED(result)) |
| 500 | { |
| 501 | ERR("Could not create additional swap chains or offscreen surfaces: %08lX", result); |
| 502 | release(); |
| 503 | |
| 504 | if (d3d11::isDeviceLostError(result)) |
| 505 | { |
| 506 | return EGL_CONTEXT_LOST; |
| 507 | } |
| 508 | else |
| 509 | { |
| 510 | return EGL_BAD_ALLOC; |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | result = mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&mBackBufferTexture); |
| 515 | ASSERT(SUCCEEDED(result)); |
| 516 | d3d11::SetDebugName(mBackBufferTexture, "Back buffer texture"); |
| 517 | |
| 518 | result = device->CreateRenderTargetView(mBackBufferTexture, NULL, &mBackBufferRTView); |
| 519 | ASSERT(SUCCEEDED(result)); |
| 520 | d3d11::SetDebugName(mBackBufferRTView, "Back buffer render target"); |
| 521 | } |
| 522 | |
shannon.woods@transgaming.com | 211fa2e | 2013-02-28 23:05:23 +0000 | [diff] [blame] | 523 | // If we are resizing the swap chain, we don't wish to recreate all the static resources |
| 524 | if (!mPassThroughResourcesInit) |
| 525 | { |
| 526 | mPassThroughResourcesInit = true; |
| 527 | initPassThroughResources(); |
| 528 | } |
| 529 | |
shannon.woods@transgaming.com | ae81383 | 2013-02-28 23:05:28 +0000 | [diff] [blame] | 530 | return resetOffscreenTexture(backbufferWidth, backbufferHeight); |
shannon.woods@transgaming.com | 211fa2e | 2013-02-28 23:05:23 +0000 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | void SwapChain11::initPassThroughResources() |
| 534 | { |
| 535 | ID3D11Device *device = mRenderer->getDevice(); |
| 536 | |
| 537 | ASSERT(device != NULL); |
| 538 | |
| 539 | // Make sure our resources are all not allocated, when we create |
| 540 | ASSERT(mQuadVB == NULL && mPassThroughSampler == NULL); |
| 541 | ASSERT(mPassThroughIL == NULL && mPassThroughVS == NULL && mPassThroughPS == NULL); |
| 542 | |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 543 | D3D11_BUFFER_DESC vbDesc; |
shannon.woods@transgaming.com | f3d8207 | 2013-01-25 21:50:43 +0000 | [diff] [blame] | 544 | vbDesc.ByteWidth = sizeof(d3d11::PositionTexCoordVertex) * 4; |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 545 | vbDesc.Usage = D3D11_USAGE_DYNAMIC; |
| 546 | vbDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; |
| 547 | vbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; |
| 548 | vbDesc.MiscFlags = 0; |
| 549 | vbDesc.StructureByteStride = 0; |
| 550 | |
shannon.woods@transgaming.com | 211fa2e | 2013-02-28 23:05:23 +0000 | [diff] [blame] | 551 | HRESULT result = device->CreateBuffer(&vbDesc, NULL, &mQuadVB); |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 552 | ASSERT(SUCCEEDED(result)); |
daniel@transgaming.com | ad3d827 | 2013-01-11 04:11:14 +0000 | [diff] [blame] | 553 | d3d11::SetDebugName(mQuadVB, "Swap chain quad vertex buffer"); |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 554 | |
| 555 | D3D11_SAMPLER_DESC samplerDesc; |
| 556 | samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT; |
| 557 | samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; |
| 558 | samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; |
| 559 | samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; |
| 560 | samplerDesc.MipLODBias = 0.0f; |
| 561 | samplerDesc.MaxAnisotropy = 0; |
| 562 | samplerDesc.ComparisonFunc = D3D11_COMPARISON_NEVER; |
| 563 | samplerDesc.BorderColor[0] = 0.0f; |
| 564 | samplerDesc.BorderColor[1] = 0.0f; |
| 565 | samplerDesc.BorderColor[2] = 0.0f; |
| 566 | samplerDesc.BorderColor[3] = 0.0f; |
| 567 | samplerDesc.MinLOD = 0; |
| 568 | samplerDesc.MaxLOD = D3D11_FLOAT32_MAX; |
| 569 | |
| 570 | result = device->CreateSamplerState(&samplerDesc, &mPassThroughSampler); |
| 571 | ASSERT(SUCCEEDED(result)); |
daniel@transgaming.com | ad3d827 | 2013-01-11 04:11:14 +0000 | [diff] [blame] | 572 | d3d11::SetDebugName(mPassThroughSampler, "Swap chain pass through sampler"); |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 573 | |
| 574 | D3D11_INPUT_ELEMENT_DESC quadLayout[] = |
| 575 | { |
| 576 | { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, |
| 577 | { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0 }, |
| 578 | }; |
| 579 | |
| 580 | result = device->CreateInputLayout(quadLayout, 2, g_VS_Passthrough, sizeof(g_VS_Passthrough), &mPassThroughIL); |
| 581 | ASSERT(SUCCEEDED(result)); |
daniel@transgaming.com | ad3d827 | 2013-01-11 04:11:14 +0000 | [diff] [blame] | 582 | d3d11::SetDebugName(mPassThroughIL, "Swap chain pass through layout"); |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 583 | |
| 584 | result = device->CreateVertexShader(g_VS_Passthrough, sizeof(g_VS_Passthrough), NULL, &mPassThroughVS); |
| 585 | ASSERT(SUCCEEDED(result)); |
daniel@transgaming.com | ad3d827 | 2013-01-11 04:11:14 +0000 | [diff] [blame] | 586 | d3d11::SetDebugName(mPassThroughVS, "Swap chain pass through vertex shader"); |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 587 | |
shannon.woods@transgaming.com | 2570c34 | 2013-01-25 21:50:22 +0000 | [diff] [blame] | 588 | result = device->CreatePixelShader(g_PS_PassthroughRGBA, sizeof(g_PS_PassthroughRGBA), NULL, &mPassThroughPS); |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 589 | ASSERT(SUCCEEDED(result)); |
daniel@transgaming.com | ad3d827 | 2013-01-11 04:11:14 +0000 | [diff] [blame] | 590 | d3d11::SetDebugName(mPassThroughPS, "Swap chain pass through pixel shader"); |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | // parameters should be validated/clamped by caller |
| 594 | EGLint SwapChain11::swapRect(EGLint x, EGLint y, EGLint width, EGLint height) |
| 595 | { |
| 596 | if (!mSwapChain) |
| 597 | { |
| 598 | return EGL_SUCCESS; |
| 599 | } |
| 600 | |
| 601 | ID3D11Device *device = mRenderer->getDevice(); |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 602 | ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 603 | |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 604 | // Set vertices |
| 605 | D3D11_MAPPED_SUBRESOURCE mappedResource; |
| 606 | HRESULT result = deviceContext->Map(mQuadVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); |
| 607 | if (FAILED(result)) |
| 608 | { |
| 609 | return EGL_BAD_ACCESS; |
| 610 | } |
| 611 | |
shannon.woods@transgaming.com | f3d8207 | 2013-01-25 21:50:43 +0000 | [diff] [blame] | 612 | d3d11::PositionTexCoordVertex *vertices = static_cast<d3d11::PositionTexCoordVertex*>(mappedResource.pData); |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 613 | |
| 614 | // Create a quad in homogeneous coordinates |
shannon.woods@transgaming.com | 2ac02d5 | 2013-01-25 21:56:54 +0000 | [diff] [blame] | 615 | float x1 = (x / float(mWidth)) * 2.0f - 1.0f; |
shannon.woods@transgaming.com | 0bbb08d | 2013-02-28 23:09:11 +0000 | [diff] [blame] | 616 | float y1 = (y / float(mHeight)) * 2.0f - 1.0f; |
shannon.woods@transgaming.com | 2ac02d5 | 2013-01-25 21:56:54 +0000 | [diff] [blame] | 617 | float x2 = ((x + width) / float(mWidth)) * 2.0f - 1.0f; |
shannon.woods@transgaming.com | 0bbb08d | 2013-02-28 23:09:11 +0000 | [diff] [blame] | 618 | float y2 = ((y + height) / float(mHeight)) * 2.0f - 1.0f; |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 619 | |
| 620 | float u1 = x / float(mWidth); |
| 621 | float v1 = y / float(mHeight); |
| 622 | float u2 = (x + width) / float(mWidth); |
| 623 | float v2 = (y + height) / float(mHeight); |
| 624 | |
shannon.woods@transgaming.com | f3d8207 | 2013-01-25 21:50:43 +0000 | [diff] [blame] | 625 | d3d11::SetPositionTexCoordVertex(&vertices[0], x1, y1, u1, v1); |
| 626 | d3d11::SetPositionTexCoordVertex(&vertices[1], x1, y2, u1, v2); |
| 627 | d3d11::SetPositionTexCoordVertex(&vertices[2], x2, y1, u2, v1); |
| 628 | d3d11::SetPositionTexCoordVertex(&vertices[3], x2, y2, u2, v2); |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 629 | |
| 630 | deviceContext->Unmap(mQuadVB, 0); |
| 631 | |
shannon.woods@transgaming.com | f3d8207 | 2013-01-25 21:50:43 +0000 | [diff] [blame] | 632 | static UINT stride = sizeof(d3d11::PositionTexCoordVertex); |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 633 | static UINT startIdx = 0; |
| 634 | deviceContext->IASetVertexBuffers(0, 1, &mQuadVB, &stride, &startIdx); |
| 635 | |
| 636 | // Apply state |
| 637 | deviceContext->OMSetDepthStencilState(NULL, 0xFFFFFFFF); |
| 638 | |
| 639 | static const float blendFactor[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; |
| 640 | deviceContext->OMSetBlendState(NULL, blendFactor, 0xFFFFFFF); |
| 641 | |
| 642 | deviceContext->RSSetState(NULL); |
| 643 | |
| 644 | // Apply shaders |
| 645 | deviceContext->IASetInputLayout(mPassThroughIL); |
| 646 | deviceContext->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); |
| 647 | deviceContext->VSSetShader(mPassThroughVS, NULL, 0); |
| 648 | deviceContext->PSSetShader(mPassThroughPS, NULL, 0); |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 649 | deviceContext->GSSetShader(NULL, NULL, 0); |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 650 | |
| 651 | // Apply render targets |
shannon.woods%transgaming.com@gtempaccount.com | ba2744f | 2013-04-13 03:33:38 +0000 | [diff] [blame] | 652 | mRenderer->setOneTimeRenderTarget(mBackBufferRTView); |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 653 | |
daniel@transgaming.com | 9799a2f | 2013-01-11 04:09:27 +0000 | [diff] [blame] | 654 | // Set the viewport |
| 655 | D3D11_VIEWPORT viewport; |
| 656 | viewport.TopLeftX = 0; |
| 657 | viewport.TopLeftY = 0; |
| 658 | viewport.Width = mWidth; |
| 659 | viewport.Height = mHeight; |
| 660 | viewport.MinDepth = 0.0f; |
| 661 | viewport.MaxDepth = 1.0f; |
| 662 | deviceContext->RSSetViewports(1, &viewport); |
| 663 | |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 664 | // Apply textures |
| 665 | deviceContext->PSSetShaderResources(0, 1, &mOffscreenSRView); |
| 666 | deviceContext->PSSetSamplers(0, 1, &mPassThroughSampler); |
| 667 | |
| 668 | // Draw |
| 669 | deviceContext->Draw(4, 0); |
shannon.woods@transgaming.com | ddd6c80 | 2013-02-28 23:05:14 +0000 | [diff] [blame] | 670 | result = mSwapChain->Present(mSwapInterval, 0); |
| 671 | |
| 672 | if (result == DXGI_ERROR_DEVICE_REMOVED) |
| 673 | { |
| 674 | HRESULT removedReason = device->GetDeviceRemovedReason(); |
| 675 | ERR("Present failed: the D3D11 device was removed: 0x%08X", removedReason); |
| 676 | return EGL_CONTEXT_LOST; |
| 677 | } |
| 678 | else if (result == DXGI_ERROR_DEVICE_RESET) |
| 679 | { |
| 680 | ERR("Present failed: the D3D11 device was reset from a bad command."); |
| 681 | return EGL_CONTEXT_LOST; |
| 682 | } |
| 683 | else if (FAILED(result)) |
| 684 | { |
| 685 | ERR("Present failed with error code 0x%08X", result); |
| 686 | } |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 687 | |
| 688 | // Unbind |
| 689 | static ID3D11ShaderResourceView *const nullSRV = NULL; |
| 690 | deviceContext->PSSetShaderResources(0, 1, &nullSRV); |
| 691 | |
shannon.woods%transgaming.com@gtempaccount.com | ba2744f | 2013-04-13 03:33:38 +0000 | [diff] [blame] | 692 | mRenderer->unapplyRenderTargets(); |
daniel@transgaming.com | e097047 | 2012-11-28 21:05:07 +0000 | [diff] [blame] | 693 | mRenderer->markAllStateDirty(); |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 694 | |
| 695 | return EGL_SUCCESS; |
| 696 | } |
| 697 | |
shannon.woods@transgaming.com | 5c25ed2 | 2013-01-25 21:49:51 +0000 | [diff] [blame] | 698 | // Increments refcount on texture. |
| 699 | // caller must Release() the returned texture |
| 700 | ID3D11Texture2D *SwapChain11::getOffscreenTexture() |
| 701 | { |
| 702 | if (mOffscreenTexture) |
| 703 | { |
| 704 | mOffscreenTexture->AddRef(); |
| 705 | } |
| 706 | |
| 707 | return mOffscreenTexture; |
| 708 | } |
| 709 | |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 710 | // Increments refcount on view. |
| 711 | // caller must Release() the returned view |
| 712 | ID3D11RenderTargetView *SwapChain11::getRenderTarget() |
| 713 | { |
daniel@transgaming.com | c8c70ad | 2012-11-28 21:04:37 +0000 | [diff] [blame] | 714 | if (mOffscreenRTView) |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 715 | { |
daniel@transgaming.com | c8c70ad | 2012-11-28 21:04:37 +0000 | [diff] [blame] | 716 | mOffscreenRTView->AddRef(); |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 717 | } |
| 718 | |
daniel@transgaming.com | c8c70ad | 2012-11-28 21:04:37 +0000 | [diff] [blame] | 719 | return mOffscreenRTView; |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | // Increments refcount on view. |
| 723 | // caller must Release() the returned view |
shannon.woods@transgaming.com | 5c25ed2 | 2013-01-25 21:49:51 +0000 | [diff] [blame] | 724 | ID3D11ShaderResourceView *SwapChain11::getRenderTargetShaderResource() |
| 725 | { |
| 726 | if (mOffscreenSRView) |
| 727 | { |
| 728 | mOffscreenSRView->AddRef(); |
| 729 | } |
| 730 | |
| 731 | return mOffscreenSRView; |
| 732 | } |
| 733 | |
| 734 | // Increments refcount on view. |
| 735 | // caller must Release() the returned view |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 736 | ID3D11DepthStencilView *SwapChain11::getDepthStencil() |
| 737 | { |
daniel@transgaming.com | c8c70ad | 2012-11-28 21:04:37 +0000 | [diff] [blame] | 738 | if (mDepthStencilDSView) |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 739 | { |
daniel@transgaming.com | c8c70ad | 2012-11-28 21:04:37 +0000 | [diff] [blame] | 740 | mDepthStencilDSView->AddRef(); |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 741 | } |
| 742 | |
daniel@transgaming.com | c8c70ad | 2012-11-28 21:04:37 +0000 | [diff] [blame] | 743 | return mDepthStencilDSView; |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 744 | } |
| 745 | |
shannon.woods@transgaming.com | 7e23285 | 2013-02-28 23:06:15 +0000 | [diff] [blame] | 746 | ID3D11Texture2D *SwapChain11::getDepthStencilTexture() |
| 747 | { |
| 748 | if (mDepthStencilTexture) |
| 749 | { |
| 750 | mDepthStencilTexture->AddRef(); |
| 751 | } |
| 752 | |
| 753 | return mDepthStencilTexture; |
| 754 | } |
| 755 | |
daniel@transgaming.com | d733bb8 | 2012-11-28 20:53:40 +0000 | [diff] [blame] | 756 | SwapChain11 *SwapChain11::makeSwapChain11(SwapChain *swapChain) |
| 757 | { |
apatrick@chromium.org | 8b400b1 | 2013-01-30 21:53:40 +0000 | [diff] [blame] | 758 | ASSERT(HAS_DYNAMIC_TYPE(rx::SwapChain11*, swapChain)); |
daniel@transgaming.com | d733bb8 | 2012-11-28 20:53:40 +0000 | [diff] [blame] | 759 | return static_cast<rx::SwapChain11*>(swapChain); |
daniel@transgaming.com | 32fdf82 | 2012-11-28 20:53:30 +0000 | [diff] [blame] | 760 | } |
daniel@transgaming.com | d733bb8 | 2012-11-28 20:53:40 +0000 | [diff] [blame] | 761 | |
shannon.woods%transgaming.com@gtempaccount.com | 8bce3f5 | 2013-04-13 03:35:32 +0000 | [diff] [blame^] | 762 | void SwapChain11::recreate() |
| 763 | { |
| 764 | // possibly should use this method instead of reset |
| 765 | } |
| 766 | |
daniel@transgaming.com | d733bb8 | 2012-11-28 20:53:40 +0000 | [diff] [blame] | 767 | } |