shannon.woods@transgaming.com | bdf2d80 | 2013-02-28 23:16:20 +0000 | [diff] [blame] | 1 | #include "precompiled.h" |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +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 | 3c72078 | 2012-10-31 18:42:34 +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 | |
daniel@transgaming.com | a27e05b | 2012-11-28 19:39:42 +0000 | [diff] [blame] | 8 | // SwapChain9.cpp: Implements a back-end specific class for the D3D9 swap chain. |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 9 | |
daniel@transgaming.com | a27e05b | 2012-11-28 19:39:42 +0000 | [diff] [blame] | 10 | #include "libGLESv2/renderer/SwapChain9.h" |
daniel@transgaming.com | a27e05b | 2012-11-28 19:39:42 +0000 | [diff] [blame] | 11 | #include "libGLESv2/renderer/renderer9_utils.h" |
shannonwoods@chromium.org | 755012f | 2013-05-30 00:09:32 +0000 | [diff] [blame] | 12 | #include "libGLESv2/renderer/formatutils9.h" |
daniel@transgaming.com | a27e05b | 2012-11-28 19:39:42 +0000 | [diff] [blame] | 13 | #include "libGLESv2/renderer/Renderer9.h" |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 14 | |
daniel@transgaming.com | 76d3e6e | 2012-10-31 19:55:33 +0000 | [diff] [blame] | 15 | namespace rx |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 16 | { |
| 17 | |
daniel@transgaming.com | a27e05b | 2012-11-28 19:39:42 +0000 | [diff] [blame] | 18 | SwapChain9::SwapChain9(Renderer9 *renderer, HWND window, HANDLE shareHandle, |
| 19 | GLenum backBufferFormat, GLenum depthBufferFormat) |
| 20 | : mRenderer(renderer), SwapChain(window, shareHandle, backBufferFormat, depthBufferFormat) |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 21 | { |
| 22 | mSwapChain = NULL; |
| 23 | mBackBuffer = NULL; |
| 24 | mDepthStencil = NULL; |
| 25 | mRenderTarget = NULL; |
| 26 | mOffscreenTexture = NULL; |
| 27 | mWidth = -1; |
| 28 | mHeight = -1; |
shannon.woods@transgaming.com | c71ca75 | 2013-02-28 23:06:50 +0000 | [diff] [blame] | 29 | mSwapInterval = -1; |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 30 | } |
| 31 | |
daniel@transgaming.com | a27e05b | 2012-11-28 19:39:42 +0000 | [diff] [blame] | 32 | SwapChain9::~SwapChain9() |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 33 | { |
| 34 | release(); |
| 35 | } |
| 36 | |
daniel@transgaming.com | a27e05b | 2012-11-28 19:39:42 +0000 | [diff] [blame] | 37 | void SwapChain9::release() |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 38 | { |
Geoff Lang | ea22863 | 2013-07-30 15:17:12 -0400 | [diff] [blame^] | 39 | SafeRelease(mSwapChain); |
| 40 | SafeRelease(mBackBuffer); |
| 41 | SafeRelease(mDepthStencil); |
| 42 | SafeRelease(mRenderTarget); |
| 43 | SafeRelease(mOffscreenTexture); |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 44 | |
daniel@transgaming.com | 21cfaef | 2012-10-31 18:42:43 +0000 | [diff] [blame] | 45 | if (mWindow) |
Geoff Lang | ea22863 | 2013-07-30 15:17:12 -0400 | [diff] [blame^] | 46 | { |
daniel@transgaming.com | 21cfaef | 2012-10-31 18:42:43 +0000 | [diff] [blame] | 47 | mShareHandle = NULL; |
Geoff Lang | ea22863 | 2013-07-30 15:17:12 -0400 | [diff] [blame^] | 48 | } |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | static DWORD convertInterval(EGLint interval) |
| 52 | { |
| 53 | switch(interval) |
| 54 | { |
| 55 | case 0: return D3DPRESENT_INTERVAL_IMMEDIATE; |
| 56 | case 1: return D3DPRESENT_INTERVAL_ONE; |
| 57 | case 2: return D3DPRESENT_INTERVAL_TWO; |
| 58 | case 3: return D3DPRESENT_INTERVAL_THREE; |
| 59 | case 4: return D3DPRESENT_INTERVAL_FOUR; |
| 60 | default: UNREACHABLE(); |
| 61 | } |
| 62 | |
| 63 | return D3DPRESENT_INTERVAL_DEFAULT; |
| 64 | } |
| 65 | |
shannon.woods@transgaming.com | c71ca75 | 2013-02-28 23:06:50 +0000 | [diff] [blame] | 66 | EGLint SwapChain9::resize(int backbufferWidth, int backbufferHeight) |
| 67 | { |
| 68 | // D3D9 does not support resizing swap chains without recreating them |
| 69 | return reset(backbufferWidth, backbufferHeight, mSwapInterval); |
| 70 | } |
| 71 | |
daniel@transgaming.com | a27e05b | 2012-11-28 19:39:42 +0000 | [diff] [blame] | 72 | EGLint SwapChain9::reset(int backbufferWidth, int backbufferHeight, EGLint swapInterval) |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 73 | { |
| 74 | IDirect3DDevice9 *device = mRenderer->getDevice(); |
| 75 | |
| 76 | if (device == NULL) |
| 77 | { |
| 78 | return EGL_BAD_ACCESS; |
| 79 | } |
| 80 | |
| 81 | // Evict all non-render target textures to system memory and release all resources |
| 82 | // before reallocating them to free up as much video memory as possible. |
| 83 | device->EvictManagedResources(); |
| 84 | |
| 85 | HRESULT result; |
| 86 | |
| 87 | // Release specific resources to free up memory for the new render target, while the |
| 88 | // old render target still exists for the purpose of preserving its contents. |
Geoff Lang | ea22863 | 2013-07-30 15:17:12 -0400 | [diff] [blame^] | 89 | SafeRelease(mSwapChain); |
| 90 | SafeRelease(mBackBuffer); |
| 91 | SafeRelease(mOffscreenTexture); |
| 92 | SafeRelease(mDepthStencil); |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 93 | |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 94 | HANDLE *pShareHandle = NULL; |
| 95 | if (!mWindow && mRenderer->getShareHandleSupport()) |
| 96 | { |
| 97 | pShareHandle = &mShareHandle; |
| 98 | } |
| 99 | |
| 100 | result = device->CreateTexture(backbufferWidth, backbufferHeight, 1, D3DUSAGE_RENDERTARGET, |
Shannon Woods | ddb785c | 2013-07-08 10:32:13 -0400 | [diff] [blame] | 101 | gl_d3d9::GetTextureFormat(mBackBufferFormat, mRenderer), |
shannonwoods@chromium.org | 755012f | 2013-05-30 00:09:32 +0000 | [diff] [blame] | 102 | D3DPOOL_DEFAULT, &mOffscreenTexture, pShareHandle); |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 103 | if (FAILED(result)) |
| 104 | { |
| 105 | ERR("Could not create offscreen texture: %08lX", result); |
| 106 | release(); |
| 107 | |
shannon.woods@transgaming.com | f5f5949 | 2013-02-28 23:04:40 +0000 | [diff] [blame] | 108 | if (d3d9::isDeviceLostError(result)) |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 109 | { |
| 110 | return EGL_CONTEXT_LOST; |
| 111 | } |
| 112 | else |
| 113 | { |
| 114 | return EGL_BAD_ALLOC; |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | IDirect3DSurface9 *oldRenderTarget = mRenderTarget; |
| 119 | |
| 120 | result = mOffscreenTexture->GetSurfaceLevel(0, &mRenderTarget); |
| 121 | ASSERT(SUCCEEDED(result)); |
| 122 | |
| 123 | if (oldRenderTarget) |
| 124 | { |
| 125 | RECT rect = |
| 126 | { |
| 127 | 0, 0, |
| 128 | mWidth, mHeight |
| 129 | }; |
| 130 | |
| 131 | if (rect.right > static_cast<LONG>(backbufferWidth)) |
| 132 | { |
| 133 | rect.right = backbufferWidth; |
| 134 | } |
| 135 | |
| 136 | if (rect.bottom > static_cast<LONG>(backbufferHeight)) |
| 137 | { |
| 138 | rect.bottom = backbufferHeight; |
| 139 | } |
| 140 | |
| 141 | mRenderer->endScene(); |
| 142 | |
| 143 | result = device->StretchRect(oldRenderTarget, &rect, mRenderTarget, &rect, D3DTEXF_NONE); |
| 144 | ASSERT(SUCCEEDED(result)); |
| 145 | |
Geoff Lang | ea22863 | 2013-07-30 15:17:12 -0400 | [diff] [blame^] | 146 | SafeRelease(oldRenderTarget); |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | if (mWindow) |
| 150 | { |
| 151 | D3DPRESENT_PARAMETERS presentParameters = {0}; |
shannonwoods@chromium.org | 755012f | 2013-05-30 00:09:32 +0000 | [diff] [blame] | 152 | presentParameters.AutoDepthStencilFormat = gl_d3d9::GetRenderFormat(mDepthBufferFormat, mRenderer); |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 153 | presentParameters.BackBufferCount = 1; |
shannonwoods@chromium.org | 755012f | 2013-05-30 00:09:32 +0000 | [diff] [blame] | 154 | presentParameters.BackBufferFormat = gl_d3d9::GetRenderFormat(mBackBufferFormat, mRenderer); |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 155 | presentParameters.EnableAutoDepthStencil = FALSE; |
| 156 | presentParameters.Flags = 0; |
| 157 | presentParameters.hDeviceWindow = mWindow; |
| 158 | presentParameters.MultiSampleQuality = 0; // FIXME: Unimplemented |
| 159 | presentParameters.MultiSampleType = D3DMULTISAMPLE_NONE; // FIXME: Unimplemented |
| 160 | presentParameters.PresentationInterval = convertInterval(swapInterval); |
| 161 | presentParameters.SwapEffect = D3DSWAPEFFECT_DISCARD; |
| 162 | presentParameters.Windowed = TRUE; |
| 163 | presentParameters.BackBufferWidth = backbufferWidth; |
| 164 | presentParameters.BackBufferHeight = backbufferHeight; |
| 165 | |
| 166 | // http://crbug.com/140239 |
| 167 | // http://crbug.com/143434 |
| 168 | // |
| 169 | // Some AMD/Intel switchable systems / drivers appear to round swap chain surfaces to a multiple of 64 pixels in width |
| 170 | // when using the integrated Intel. This rounds the width up rather than down. |
| 171 | // |
| 172 | // Some non-switchable AMD GPUs / drivers do not respect the source rectangle to Present. Therefore, when the vendor ID |
| 173 | // is not Intel, the back buffer width must be exactly the same width as the window or horizontal scaling will occur. |
daniel@transgaming.com | d8e3656 | 2012-10-31 19:52:19 +0000 | [diff] [blame] | 174 | if (mRenderer->getAdapterVendor() == VENDOR_ID_INTEL) |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 175 | { |
| 176 | presentParameters.BackBufferWidth = (presentParameters.BackBufferWidth + 63) / 64 * 64; |
| 177 | } |
| 178 | |
| 179 | result = device->CreateAdditionalSwapChain(&presentParameters, &mSwapChain); |
| 180 | |
| 181 | if (FAILED(result)) |
| 182 | { |
| 183 | ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY || result == D3DERR_INVALIDCALL || result == D3DERR_DEVICELOST); |
| 184 | |
| 185 | ERR("Could not create additional swap chains or offscreen surfaces: %08lX", result); |
| 186 | release(); |
| 187 | |
shannon.woods@transgaming.com | f5f5949 | 2013-02-28 23:04:40 +0000 | [diff] [blame] | 188 | if (d3d9::isDeviceLostError(result)) |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 189 | { |
| 190 | return EGL_CONTEXT_LOST; |
| 191 | } |
| 192 | else |
| 193 | { |
| 194 | return EGL_BAD_ALLOC; |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | result = mSwapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &mBackBuffer); |
| 199 | ASSERT(SUCCEEDED(result)); |
daniel@transgaming.com | b323df0 | 2012-11-28 19:41:36 +0000 | [diff] [blame] | 200 | InvalidateRect(mWindow, NULL, FALSE); |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 201 | } |
| 202 | |
daniel@transgaming.com | a60160b | 2012-11-28 19:41:15 +0000 | [diff] [blame] | 203 | if (mDepthBufferFormat != GL_NONE) |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 204 | { |
| 205 | result = device->CreateDepthStencilSurface(backbufferWidth, backbufferHeight, |
shannonwoods@chromium.org | 755012f | 2013-05-30 00:09:32 +0000 | [diff] [blame] | 206 | gl_d3d9::GetRenderFormat(mDepthBufferFormat, mRenderer), |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 207 | D3DMULTISAMPLE_NONE, 0, FALSE, &mDepthStencil, NULL); |
| 208 | |
| 209 | if (FAILED(result)) |
| 210 | { |
| 211 | ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY || result == D3DERR_INVALIDCALL); |
| 212 | |
| 213 | ERR("Could not create depthstencil surface for new swap chain: 0x%08X", result); |
| 214 | release(); |
| 215 | |
shannon.woods@transgaming.com | f5f5949 | 2013-02-28 23:04:40 +0000 | [diff] [blame] | 216 | if (d3d9::isDeviceLostError(result)) |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 217 | { |
| 218 | return EGL_CONTEXT_LOST; |
| 219 | } |
| 220 | else |
| 221 | { |
| 222 | return EGL_BAD_ALLOC; |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | mWidth = backbufferWidth; |
| 228 | mHeight = backbufferHeight; |
shannon.woods@transgaming.com | c71ca75 | 2013-02-28 23:06:50 +0000 | [diff] [blame] | 229 | mSwapInterval = swapInterval; |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 230 | |
| 231 | return EGL_SUCCESS; |
| 232 | } |
| 233 | |
| 234 | // parameters should be validated/clamped by caller |
daniel@transgaming.com | a27e05b | 2012-11-28 19:39:42 +0000 | [diff] [blame] | 235 | EGLint SwapChain9::swapRect(EGLint x, EGLint y, EGLint width, EGLint height) |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 236 | { |
| 237 | if (!mSwapChain) |
| 238 | { |
| 239 | return EGL_SUCCESS; |
| 240 | } |
| 241 | |
| 242 | IDirect3DDevice9 *device = mRenderer->getDevice(); |
| 243 | |
| 244 | // Disable all pipeline operations |
| 245 | device->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE); |
| 246 | device->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); |
| 247 | device->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); |
| 248 | device->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); |
| 249 | device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); |
| 250 | device->SetRenderState(D3DRS_STENCILENABLE, FALSE); |
| 251 | device->SetRenderState(D3DRS_CLIPPLANEENABLE, 0); |
| 252 | device->SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_ALPHA | D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_RED); |
| 253 | device->SetRenderState(D3DRS_SRGBWRITEENABLE, FALSE); |
| 254 | device->SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE); |
| 255 | device->SetPixelShader(NULL); |
| 256 | device->SetVertexShader(NULL); |
| 257 | |
| 258 | device->SetRenderTarget(0, mBackBuffer); |
| 259 | device->SetDepthStencilSurface(NULL); |
| 260 | |
| 261 | device->SetTexture(0, mOffscreenTexture); |
| 262 | device->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); |
| 263 | device->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); |
| 264 | device->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); |
| 265 | device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT); |
| 266 | device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT); |
| 267 | device->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); |
| 268 | device->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); |
| 269 | device->SetFVF(D3DFVF_XYZRHW | D3DFVF_TEX1); |
| 270 | |
| 271 | D3DVIEWPORT9 viewport = {0, 0, mWidth, mHeight, 0.0f, 1.0f}; |
| 272 | device->SetViewport(&viewport); |
| 273 | |
| 274 | float x1 = x - 0.5f; |
| 275 | float y1 = (mHeight - y - height) - 0.5f; |
| 276 | float x2 = (x + width) - 0.5f; |
| 277 | float y2 = (mHeight - y) - 0.5f; |
| 278 | |
| 279 | float u1 = x / float(mWidth); |
| 280 | float v1 = y / float(mHeight); |
| 281 | float u2 = (x + width) / float(mWidth); |
| 282 | float v2 = (y + height) / float(mHeight); |
| 283 | |
| 284 | float quad[4][6] = {{x1, y1, 0.0f, 1.0f, u1, v2}, |
| 285 | {x2, y1, 0.0f, 1.0f, u2, v2}, |
| 286 | {x2, y2, 0.0f, 1.0f, u2, v1}, |
| 287 | {x1, y2, 0.0f, 1.0f, u1, v1}}; // x, y, z, rhw, u, v |
| 288 | |
| 289 | mRenderer->startScene(); |
| 290 | device->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, quad, 6 * sizeof(float)); |
| 291 | mRenderer->endScene(); |
| 292 | |
| 293 | device->SetTexture(0, NULL); |
| 294 | |
| 295 | RECT rect = |
| 296 | { |
| 297 | x, mHeight - y - height, |
| 298 | x + width, mHeight - y |
| 299 | }; |
| 300 | |
| 301 | HRESULT result = mSwapChain->Present(&rect, &rect, NULL, NULL, 0); |
| 302 | |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 303 | mRenderer->markAllStateDirty(); |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 304 | |
shannon.woods@transgaming.com | f5f5949 | 2013-02-28 23:04:40 +0000 | [diff] [blame] | 305 | if (d3d9::isDeviceLostError(result)) |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 306 | { |
| 307 | return EGL_CONTEXT_LOST; |
| 308 | } |
| 309 | |
| 310 | if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY || result == D3DERR_DRIVERINTERNALERROR) |
| 311 | { |
| 312 | return EGL_BAD_ALLOC; |
| 313 | } |
| 314 | |
| 315 | ASSERT(SUCCEEDED(result)); |
| 316 | |
| 317 | return EGL_SUCCESS; |
| 318 | } |
| 319 | |
| 320 | // Increments refcount on surface. |
| 321 | // caller must Release() the returned surface |
daniel@transgaming.com | a27e05b | 2012-11-28 19:39:42 +0000 | [diff] [blame] | 322 | IDirect3DSurface9 *SwapChain9::getRenderTarget() |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 323 | { |
| 324 | if (mRenderTarget) |
| 325 | { |
| 326 | mRenderTarget->AddRef(); |
| 327 | } |
| 328 | |
| 329 | return mRenderTarget; |
| 330 | } |
| 331 | |
| 332 | // Increments refcount on surface. |
| 333 | // caller must Release() the returned surface |
daniel@transgaming.com | a27e05b | 2012-11-28 19:39:42 +0000 | [diff] [blame] | 334 | IDirect3DSurface9 *SwapChain9::getDepthStencil() |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 335 | { |
| 336 | if (mDepthStencil) |
| 337 | { |
| 338 | mDepthStencil->AddRef(); |
| 339 | } |
| 340 | |
| 341 | return mDepthStencil; |
| 342 | } |
| 343 | |
| 344 | // Increments refcount on texture. |
| 345 | // caller must Release() the returned texture |
daniel@transgaming.com | a27e05b | 2012-11-28 19:39:42 +0000 | [diff] [blame] | 346 | IDirect3DTexture9 *SwapChain9::getOffscreenTexture() |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 347 | { |
| 348 | if (mOffscreenTexture) |
| 349 | { |
| 350 | mOffscreenTexture->AddRef(); |
| 351 | } |
| 352 | |
| 353 | return mOffscreenTexture; |
| 354 | } |
| 355 | |
daniel@transgaming.com | d733bb8 | 2012-11-28 20:53:40 +0000 | [diff] [blame] | 356 | SwapChain9 *SwapChain9::makeSwapChain9(SwapChain *swapChain) |
| 357 | { |
apatrick@chromium.org | 8b400b1 | 2013-01-30 21:53:40 +0000 | [diff] [blame] | 358 | ASSERT(HAS_DYNAMIC_TYPE(rx::SwapChain9*, swapChain)); |
daniel@transgaming.com | d733bb8 | 2012-11-28 20:53:40 +0000 | [diff] [blame] | 359 | return static_cast<rx::SwapChain9*>(swapChain); |
| 360 | } |
| 361 | |
shannon.woods%transgaming.com@gtempaccount.com | 8bce3f5 | 2013-04-13 03:35:32 +0000 | [diff] [blame] | 362 | void SwapChain9::recreate() |
| 363 | { |
| 364 | if (!mSwapChain) |
| 365 | { |
| 366 | return; |
| 367 | } |
| 368 | |
| 369 | IDirect3DDevice9 *device = mRenderer->getDevice(); |
| 370 | if (device == NULL) |
| 371 | { |
| 372 | return; |
| 373 | } |
| 374 | |
| 375 | D3DPRESENT_PARAMETERS presentParameters; |
| 376 | HRESULT result = mSwapChain->GetPresentParameters(&presentParameters); |
| 377 | ASSERT(SUCCEEDED(result)); |
| 378 | |
| 379 | IDirect3DSwapChain9* newSwapChain = NULL; |
| 380 | result = device->CreateAdditionalSwapChain(&presentParameters, &newSwapChain); |
| 381 | if (FAILED(result)) |
| 382 | { |
| 383 | return; |
| 384 | } |
| 385 | |
Geoff Lang | ea22863 | 2013-07-30 15:17:12 -0400 | [diff] [blame^] | 386 | SafeRelease(mSwapChain); |
shannon.woods%transgaming.com@gtempaccount.com | 8bce3f5 | 2013-04-13 03:35:32 +0000 | [diff] [blame] | 387 | mSwapChain = newSwapChain; |
| 388 | |
Geoff Lang | ea22863 | 2013-07-30 15:17:12 -0400 | [diff] [blame^] | 389 | SafeRelease(mBackBuffer); |
shannon.woods%transgaming.com@gtempaccount.com | 8bce3f5 | 2013-04-13 03:35:32 +0000 | [diff] [blame] | 390 | result = mSwapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &mBackBuffer); |
| 391 | ASSERT(SUCCEEDED(result)); |
| 392 | } |
| 393 | |
daniel@transgaming.com | 3c72078 | 2012-10-31 18:42:34 +0000 | [diff] [blame] | 394 | } |