blob: 508762629251ae774a873c5dae64df03bd47dac4 [file] [log] [blame]
daniel@transgaming.com32fdf822012-11-28 20:53:30 +00001//
daniel@transgaming.comed36abd2013-01-11 21:15:58 +00002// Copyright (c) 2012-2013 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com32fdf822012-11-28 20:53:30 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// SwapChain11.cpp: Implements a back-end specific class for the D3D11 swap chain.
8
9#include "libGLESv2/renderer/SwapChain11.h"
10
11#include "common/debug.h"
12#include "libGLESv2/utilities.h"
13#include "libGLESv2/renderer/renderer11_utils.h"
14#include "libGLESv2/renderer/Renderer11.h"
15#include "libGLESv2/Context.h"
16#include "libGLESv2/main.h"
17
daniel@transgaming.com8dc8e272013-01-11 04:10:45 +000018#include "libGLESv2/renderer/shaders/compiled/passthrough11vs.h"
shannon.woods@transgaming.com2570c342013-01-25 21:50:22 +000019#include "libGLESv2/renderer/shaders/compiled/passthroughrgba11ps.h"
daniel@transgaming.come0970472012-11-28 21:05:07 +000020
daniel@transgaming.com32fdf822012-11-28 20:53:30 +000021namespace rx
22{
23
24SwapChain11::SwapChain11(Renderer11 *renderer, HWND window, HANDLE shareHandle,
25 GLenum backBufferFormat, GLenum depthBufferFormat)
26 : mRenderer(renderer), SwapChain(window, shareHandle, backBufferFormat, depthBufferFormat)
27{
28 mSwapChain = NULL;
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +000029 mBackBufferTexture = NULL;
30 mBackBufferRTView = NULL;
daniel@transgaming.com32fdf822012-11-28 20:53:30 +000031 mOffscreenTexture = NULL;
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +000032 mOffscreenRTView = NULL;
daniel@transgaming.come0970472012-11-28 21:05:07 +000033 mOffscreenSRView = NULL;
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +000034 mDepthStencilTexture = NULL;
35 mDepthStencilDSView = NULL;
daniel@transgaming.comf06e5392013-01-11 21:15:50 +000036 mQuadVB = NULL;
37 mPassThroughSampler = NULL;
38 mPassThroughIL = NULL;
39 mPassThroughVS = NULL;
40 mPassThroughPS = NULL;
daniel@transgaming.com32fdf822012-11-28 20:53:30 +000041 mWidth = -1;
42 mHeight = -1;
43}
44
45SwapChain11::~SwapChain11()
46{
47 release();
48}
49
50void SwapChain11::release()
51{
52 if (mSwapChain)
53 {
54 mSwapChain->Release();
55 mSwapChain = NULL;
56 }
57
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +000058 if (mBackBufferTexture)
daniel@transgaming.com32fdf822012-11-28 20:53:30 +000059 {
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +000060 mBackBufferTexture->Release();
61 mBackBufferTexture = NULL;
daniel@transgaming.com32fdf822012-11-28 20:53:30 +000062 }
63
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +000064 if (mBackBufferRTView)
daniel@transgaming.com32fdf822012-11-28 20:53:30 +000065 {
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +000066 mBackBufferRTView->Release();
67 mBackBufferRTView = NULL;
daniel@transgaming.com32fdf822012-11-28 20:53:30 +000068 }
69
70 if (mOffscreenTexture)
71 {
72 mOffscreenTexture->Release();
73 mOffscreenTexture = NULL;
74 }
75
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +000076 if (mOffscreenRTView)
77 {
78 mOffscreenRTView->Release();
79 mOffscreenRTView = NULL;
80 }
81
daniel@transgaming.come0970472012-11-28 21:05:07 +000082 if (mOffscreenSRView)
83 {
84 mOffscreenSRView->Release();
85 mOffscreenSRView = NULL;
86 }
87
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +000088 if (mDepthStencilTexture)
89 {
90 mDepthStencilTexture->Release();
91 mDepthStencilTexture = NULL;
92 }
93
94 if (mDepthStencilDSView)
95 {
96 mDepthStencilDSView->Release();
97 mDepthStencilDSView = NULL;
98 }
99
daniel@transgaming.come0970472012-11-28 21:05:07 +0000100 if (mQuadVB)
101 {
102 mQuadVB->Release();
103 mQuadVB = NULL;
104 }
105
106 if (mPassThroughSampler)
107 {
108 mPassThroughSampler->Release();
109 mPassThroughSampler = NULL;
110 }
111
112 if (mPassThroughIL)
113 {
114 mPassThroughIL->Release();
115 mPassThroughIL = NULL;
116 }
117
118 if (mPassThroughVS)
119 {
120 mPassThroughVS->Release();
121 mPassThroughVS = NULL;
122 }
123
124 if (mPassThroughPS)
125 {
126 mPassThroughPS->Release();
127 mPassThroughPS = NULL;
128 }
129
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000130 if (mWindow)
131 mShareHandle = NULL;
132}
133
134EGLint SwapChain11::reset(int backbufferWidth, int backbufferHeight, EGLint swapInterval)
135{
136 ID3D11Device *device = mRenderer->getDevice();
137
138 if (device == NULL)
139 {
140 return EGL_BAD_ACCESS;
141 }
142
143 // Release specific resources to free up memory for the new render target, while the
144 // old render target still exists for the purpose of preserving its contents.
145 if (mSwapChain)
146 {
147 mSwapChain->Release();
148 mSwapChain = NULL;
149 }
150
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000151 if (mBackBufferTexture)
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000152 {
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000153 mBackBufferTexture->Release();
154 mBackBufferTexture = NULL;
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000155 }
156
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000157 if (mBackBufferRTView)
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000158 {
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000159 mBackBufferRTView->Release();
160 mBackBufferRTView = NULL;
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000161 }
162
163 if (mOffscreenTexture)
164 {
165 mOffscreenTexture->Release();
166 mOffscreenTexture = NULL;
167 }
168
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000169 if (mOffscreenRTView) // TODO: Preserve the render target content
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000170 {
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000171 mOffscreenRTView->Release();
172 mOffscreenRTView = NULL;
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000173 }
174
daniel@transgaming.come0970472012-11-28 21:05:07 +0000175 if (mOffscreenSRView)
176 {
177 mOffscreenSRView->Release();
178 mOffscreenSRView = NULL;
179 }
180
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000181 if (mDepthStencilTexture)
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000182 {
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000183 mDepthStencilTexture->Release();
184 mDepthStencilTexture = NULL;
185 }
186
187 if (mDepthStencilDSView)
188 {
189 mDepthStencilDSView->Release();
190 mDepthStencilDSView = NULL;
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000191 }
192
193 HANDLE *pShareHandle = NULL;
194 if (!mWindow && mRenderer->getShareHandleSupport())
195 {
196 pShareHandle = &mShareHandle;
197 }
198
199 D3D11_TEXTURE2D_DESC offscreenTextureDesc = {0};
200 offscreenTextureDesc.Width = backbufferWidth;
201 offscreenTextureDesc.Height = backbufferHeight;
202 offscreenTextureDesc.Format = gl_d3d11::ConvertRenderbufferFormat(mBackBufferFormat);
203 offscreenTextureDesc.MipLevels = 1;
204 offscreenTextureDesc.ArraySize = 1;
205 offscreenTextureDesc.SampleDesc.Count = 1;
206 offscreenTextureDesc.SampleDesc.Quality = 0;
207 offscreenTextureDesc.Usage = D3D11_USAGE_DEFAULT;
daniel@transgaming.come0970472012-11-28 21:05:07 +0000208 offscreenTextureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000209 offscreenTextureDesc.CPUAccessFlags = 0;
210 offscreenTextureDesc.MiscFlags = 0; // D3D11_RESOURCE_MISC_SHARED
211
212 HRESULT result = device->CreateTexture2D(&offscreenTextureDesc, NULL, &mOffscreenTexture);
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000213 d3d11::SetDebugName(mOffscreenTexture, "Offscreen texture");
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000214
215 if (FAILED(result))
216 {
217 ERR("Could not create offscreen texture: %08lX", result);
218 release();
219
220 if (isDeviceLostError(result))
221 {
222 return EGL_CONTEXT_LOST;
223 }
224 else
225 {
226 return EGL_BAD_ALLOC;
227 }
228 }
229
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000230 result = device->CreateRenderTargetView(mOffscreenTexture, NULL, &mOffscreenRTView);
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000231 ASSERT(SUCCEEDED(result));
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000232 d3d11::SetDebugName(mOffscreenRTView, "Offscreen render target");
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000233
daniel@transgaming.come0970472012-11-28 21:05:07 +0000234 result = device->CreateShaderResourceView(mOffscreenTexture, NULL, &mOffscreenSRView);
235 ASSERT(SUCCEEDED(result));
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000236 d3d11::SetDebugName(mOffscreenSRView, "Offscreen shader resource");
daniel@transgaming.come0970472012-11-28 21:05:07 +0000237
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000238 if (mWindow)
239 {
shannon.woods@transgaming.com7d4b4822013-01-25 21:52:27 +0000240 // We cannot create a swap chain for an HWND that is owned by a different process
241 DWORD currentProcessId = GetCurrentProcessId();
242 DWORD wndProcessId;
243 GetWindowThreadProcessId(mWindow, &wndProcessId);
244
245 if (currentProcessId != wndProcessId)
246 {
247 ERR("Could not create swap chain, window owned by different process");
248 release();
249 return EGL_BAD_NATIVE_WINDOW;
250 }
251
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000252 IDXGIFactory *factory = mRenderer->getDxgiFactory();
253
254 DXGI_SWAP_CHAIN_DESC swapChainDesc = {0};
255 swapChainDesc.BufferCount = 2;
256 swapChainDesc.BufferDesc.Format = gl_d3d11::ConvertRenderbufferFormat(mBackBufferFormat);
daniel@transgaming.com567b9cf2012-11-28 21:04:46 +0000257 swapChainDesc.BufferDesc.Width = backbufferWidth;
258 swapChainDesc.BufferDesc.Height = backbufferHeight;
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000259 swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
260 swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
261 swapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
262 swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
263 swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
264 swapChainDesc.Flags = 0;
265 swapChainDesc.OutputWindow = mWindow;
266 swapChainDesc.SampleDesc.Count = 1;
267 swapChainDesc.SampleDesc.Quality = 0;
268 swapChainDesc.Windowed = TRUE;
269
270 result = factory->CreateSwapChain(device, &swapChainDesc, &mSwapChain);
271
272 if (FAILED(result))
273 {
274 ERR("Could not create additional swap chains or offscreen surfaces: %08lX", result);
275 release();
276
277 if (isDeviceLostError(result))
278 {
279 return EGL_CONTEXT_LOST;
280 }
281 else
282 {
283 return EGL_BAD_ALLOC;
284 }
285 }
286
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000287 result = mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&mBackBufferTexture);
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000288 ASSERT(SUCCEEDED(result));
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000289 d3d11::SetDebugName(mBackBufferTexture, "Back buffer texture");
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000290
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000291 result = device->CreateRenderTargetView(mBackBufferTexture, NULL, &mBackBufferRTView);
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000292 ASSERT(SUCCEEDED(result));
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000293 d3d11::SetDebugName(mBackBufferRTView, "Back buffer render target");
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000294 }
295
296 if (mDepthBufferFormat != GL_NONE)
297 {
298 D3D11_TEXTURE2D_DESC depthStencilDesc = {0};
299 depthStencilDesc.Width = backbufferWidth;
300 depthStencilDesc.Height = backbufferHeight;
301 depthStencilDesc.Format = gl_d3d11::ConvertRenderbufferFormat(mDepthBufferFormat);
302 depthStencilDesc.MipLevels = 1;
303 depthStencilDesc.ArraySize = 1;
304 depthStencilDesc.SampleDesc.Count = 1;
305 depthStencilDesc.SampleDesc.Quality = 0;
306 depthStencilDesc.Usage = D3D11_USAGE_DEFAULT;
307 depthStencilDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
308 depthStencilDesc.CPUAccessFlags = 0;
309 depthStencilDesc.MiscFlags = 0;
310
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000311 result = device->CreateTexture2D(&depthStencilDesc, NULL, &mDepthStencilTexture);
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000312 if (FAILED(result))
313 {
314 ERR("Could not create depthstencil surface for new swap chain: 0x%08X", result);
315 release();
316
317 if (isDeviceLostError(result))
318 {
319 return EGL_CONTEXT_LOST;
320 }
321 else
322 {
323 return EGL_BAD_ALLOC;
324 }
325 }
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000326 d3d11::SetDebugName(mDepthStencilTexture, "Depth stencil texture");
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000327
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000328 result = device->CreateDepthStencilView(mDepthStencilTexture, NULL, &mDepthStencilDSView);
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000329 ASSERT(SUCCEEDED(result));
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000330 d3d11::SetDebugName(mDepthStencilDSView, "Depth stencil view");
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000331 }
332
daniel@transgaming.come0970472012-11-28 21:05:07 +0000333 D3D11_BUFFER_DESC vbDesc;
shannon.woods@transgaming.comf3d82072013-01-25 21:50:43 +0000334 vbDesc.ByteWidth = sizeof(d3d11::PositionTexCoordVertex) * 4;
daniel@transgaming.come0970472012-11-28 21:05:07 +0000335 vbDesc.Usage = D3D11_USAGE_DYNAMIC;
336 vbDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
337 vbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
338 vbDesc.MiscFlags = 0;
339 vbDesc.StructureByteStride = 0;
340
341 result = device->CreateBuffer(&vbDesc, NULL, &mQuadVB);
342 ASSERT(SUCCEEDED(result));
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000343 d3d11::SetDebugName(mQuadVB, "Swap chain quad vertex buffer");
daniel@transgaming.come0970472012-11-28 21:05:07 +0000344
345 D3D11_SAMPLER_DESC samplerDesc;
346 samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
347 samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
348 samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
349 samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
350 samplerDesc.MipLODBias = 0.0f;
351 samplerDesc.MaxAnisotropy = 0;
352 samplerDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
353 samplerDesc.BorderColor[0] = 0.0f;
354 samplerDesc.BorderColor[1] = 0.0f;
355 samplerDesc.BorderColor[2] = 0.0f;
356 samplerDesc.BorderColor[3] = 0.0f;
357 samplerDesc.MinLOD = 0;
358 samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
359
360 result = device->CreateSamplerState(&samplerDesc, &mPassThroughSampler);
361 ASSERT(SUCCEEDED(result));
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000362 d3d11::SetDebugName(mPassThroughSampler, "Swap chain pass through sampler");
daniel@transgaming.come0970472012-11-28 21:05:07 +0000363
364 D3D11_INPUT_ELEMENT_DESC quadLayout[] =
365 {
366 { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
367 { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0 },
368 };
369
370 result = device->CreateInputLayout(quadLayout, 2, g_VS_Passthrough, sizeof(g_VS_Passthrough), &mPassThroughIL);
371 ASSERT(SUCCEEDED(result));
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000372 d3d11::SetDebugName(mPassThroughIL, "Swap chain pass through layout");
daniel@transgaming.come0970472012-11-28 21:05:07 +0000373
374 result = device->CreateVertexShader(g_VS_Passthrough, sizeof(g_VS_Passthrough), NULL, &mPassThroughVS);
375 ASSERT(SUCCEEDED(result));
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000376 d3d11::SetDebugName(mPassThroughVS, "Swap chain pass through vertex shader");
daniel@transgaming.come0970472012-11-28 21:05:07 +0000377
shannon.woods@transgaming.com2570c342013-01-25 21:50:22 +0000378 result = device->CreatePixelShader(g_PS_PassthroughRGBA, sizeof(g_PS_PassthroughRGBA), NULL, &mPassThroughPS);
daniel@transgaming.come0970472012-11-28 21:05:07 +0000379 ASSERT(SUCCEEDED(result));
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000380 d3d11::SetDebugName(mPassThroughPS, "Swap chain pass through pixel shader");
daniel@transgaming.come0970472012-11-28 21:05:07 +0000381
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000382 mWidth = backbufferWidth;
383 mHeight = backbufferHeight;
384
385 return EGL_SUCCESS;
386}
387
388// parameters should be validated/clamped by caller
389EGLint SwapChain11::swapRect(EGLint x, EGLint y, EGLint width, EGLint height)
390{
391 if (!mSwapChain)
392 {
393 return EGL_SUCCESS;
394 }
395
396 ID3D11Device *device = mRenderer->getDevice();
daniel@transgaming.come0970472012-11-28 21:05:07 +0000397 ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000398
daniel@transgaming.come0970472012-11-28 21:05:07 +0000399 // Set vertices
400 D3D11_MAPPED_SUBRESOURCE mappedResource;
401 HRESULT result = deviceContext->Map(mQuadVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
402 if (FAILED(result))
403 {
404 return EGL_BAD_ACCESS;
405 }
406
shannon.woods@transgaming.comf3d82072013-01-25 21:50:43 +0000407 d3d11::PositionTexCoordVertex *vertices = static_cast<d3d11::PositionTexCoordVertex*>(mappedResource.pData);
daniel@transgaming.come0970472012-11-28 21:05:07 +0000408
409 // Create a quad in homogeneous coordinates
410 float x1 = (x / mWidth) * 2.0f - 1.0f;
411 float y1 = ((mHeight - y - height) / mHeight) * 2.0f - 1.0f;
412 float x2 = ((x + width) / mWidth) * 2.0f - 1.0f;
413 float y2 = ((mHeight - y) / mHeight) * 2.0f - 1.0f;
414
415 float u1 = x / float(mWidth);
416 float v1 = y / float(mHeight);
417 float u2 = (x + width) / float(mWidth);
418 float v2 = (y + height) / float(mHeight);
419
shannon.woods@transgaming.comf3d82072013-01-25 21:50:43 +0000420 d3d11::SetPositionTexCoordVertex(&vertices[0], x1, y1, u1, v1);
421 d3d11::SetPositionTexCoordVertex(&vertices[1], x1, y2, u1, v2);
422 d3d11::SetPositionTexCoordVertex(&vertices[2], x2, y1, u2, v1);
423 d3d11::SetPositionTexCoordVertex(&vertices[3], x2, y2, u2, v2);
daniel@transgaming.come0970472012-11-28 21:05:07 +0000424
425 deviceContext->Unmap(mQuadVB, 0);
426
shannon.woods@transgaming.comf3d82072013-01-25 21:50:43 +0000427 static UINT stride = sizeof(d3d11::PositionTexCoordVertex);
daniel@transgaming.come0970472012-11-28 21:05:07 +0000428 static UINT startIdx = 0;
429 deviceContext->IASetVertexBuffers(0, 1, &mQuadVB, &stride, &startIdx);
430
431 // Apply state
432 deviceContext->OMSetDepthStencilState(NULL, 0xFFFFFFFF);
433
434 static const float blendFactor[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
435 deviceContext->OMSetBlendState(NULL, blendFactor, 0xFFFFFFF);
436
437 deviceContext->RSSetState(NULL);
438
439 // Apply shaders
440 deviceContext->IASetInputLayout(mPassThroughIL);
441 deviceContext->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
442 deviceContext->VSSetShader(mPassThroughVS, NULL, 0);
443 deviceContext->PSSetShader(mPassThroughPS, NULL, 0);
444
445 // Apply render targets
446 deviceContext->OMSetRenderTargets(1, &mBackBufferRTView, NULL);
447
daniel@transgaming.com9799a2f2013-01-11 04:09:27 +0000448 // Set the viewport
449 D3D11_VIEWPORT viewport;
450 viewport.TopLeftX = 0;
451 viewport.TopLeftY = 0;
452 viewport.Width = mWidth;
453 viewport.Height = mHeight;
454 viewport.MinDepth = 0.0f;
455 viewport.MaxDepth = 1.0f;
456 deviceContext->RSSetViewports(1, &viewport);
457
daniel@transgaming.come0970472012-11-28 21:05:07 +0000458 // Apply textures
459 deviceContext->PSSetShaderResources(0, 1, &mOffscreenSRView);
460 deviceContext->PSSetSamplers(0, 1, &mPassThroughSampler);
461
462 // Draw
463 deviceContext->Draw(4, 0);
464 mSwapChain->Present(0, 0);
465
466 // Unbind
467 static ID3D11ShaderResourceView *const nullSRV = NULL;
468 deviceContext->PSSetShaderResources(0, 1, &nullSRV);
469
470 static ID3D11RenderTargetView *const nullRTV = NULL;
471 deviceContext->OMSetRenderTargets(1, &nullRTV, NULL);
472
daniel@transgaming.come0970472012-11-28 21:05:07 +0000473 mRenderer->markAllStateDirty();
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000474
475 return EGL_SUCCESS;
476}
477
shannon.woods@transgaming.com5c25ed22013-01-25 21:49:51 +0000478// Increments refcount on texture.
479// caller must Release() the returned texture
480ID3D11Texture2D *SwapChain11::getOffscreenTexture()
481{
482 if (mOffscreenTexture)
483 {
484 mOffscreenTexture->AddRef();
485 }
486
487 return mOffscreenTexture;
488}
489
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000490// Increments refcount on view.
491// caller must Release() the returned view
492ID3D11RenderTargetView *SwapChain11::getRenderTarget()
493{
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000494 if (mOffscreenRTView)
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000495 {
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000496 mOffscreenRTView->AddRef();
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000497 }
498
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000499 return mOffscreenRTView;
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000500}
501
502// Increments refcount on view.
503// caller must Release() the returned view
shannon.woods@transgaming.com5c25ed22013-01-25 21:49:51 +0000504ID3D11ShaderResourceView *SwapChain11::getRenderTargetShaderResource()
505{
506 if (mOffscreenSRView)
507 {
508 mOffscreenSRView->AddRef();
509 }
510
511 return mOffscreenSRView;
512}
513
514// Increments refcount on view.
515// caller must Release() the returned view
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000516ID3D11DepthStencilView *SwapChain11::getDepthStencil()
517{
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000518 if (mDepthStencilDSView)
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000519 {
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000520 mDepthStencilDSView->AddRef();
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000521 }
522
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000523 return mDepthStencilDSView;
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000524}
525
daniel@transgaming.comd733bb82012-11-28 20:53:40 +0000526SwapChain11 *SwapChain11::makeSwapChain11(SwapChain *swapChain)
527{
528 ASSERT(dynamic_cast<rx::SwapChain11*>(swapChain) != NULL);
529 return static_cast<rx::SwapChain11*>(swapChain);
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000530}
daniel@transgaming.comd733bb82012-11-28 20:53:40 +0000531
532}