blob: 55d42e6843185fd48495610fe23a429d8e3c2f6d [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
daniel@transgaming.come0970472012-11-28 21:05:07 +000024struct QuadVertex
25{
26 float x, y;
27 float u, v;
28};
29
30static void setVertex(QuadVertex* vertex, float x, float y, float u, float v)
31{
32 vertex->x = x;
33 vertex->y = y;
34 vertex->u = u;
35 vertex->v = v;
36}
37
daniel@transgaming.com32fdf822012-11-28 20:53:30 +000038SwapChain11::SwapChain11(Renderer11 *renderer, HWND window, HANDLE shareHandle,
39 GLenum backBufferFormat, GLenum depthBufferFormat)
40 : mRenderer(renderer), SwapChain(window, shareHandle, backBufferFormat, depthBufferFormat)
41{
42 mSwapChain = NULL;
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +000043 mBackBufferTexture = NULL;
44 mBackBufferRTView = NULL;
daniel@transgaming.com32fdf822012-11-28 20:53:30 +000045 mOffscreenTexture = NULL;
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +000046 mOffscreenRTView = NULL;
daniel@transgaming.come0970472012-11-28 21:05:07 +000047 mOffscreenSRView = NULL;
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +000048 mDepthStencilTexture = NULL;
49 mDepthStencilDSView = NULL;
daniel@transgaming.comf06e5392013-01-11 21:15:50 +000050 mQuadVB = NULL;
51 mPassThroughSampler = NULL;
52 mPassThroughIL = NULL;
53 mPassThroughVS = NULL;
54 mPassThroughPS = NULL;
daniel@transgaming.com32fdf822012-11-28 20:53:30 +000055 mWidth = -1;
56 mHeight = -1;
57}
58
59SwapChain11::~SwapChain11()
60{
61 release();
62}
63
64void SwapChain11::release()
65{
66 if (mSwapChain)
67 {
68 mSwapChain->Release();
69 mSwapChain = NULL;
70 }
71
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +000072 if (mBackBufferTexture)
daniel@transgaming.com32fdf822012-11-28 20:53:30 +000073 {
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +000074 mBackBufferTexture->Release();
75 mBackBufferTexture = NULL;
daniel@transgaming.com32fdf822012-11-28 20:53:30 +000076 }
77
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +000078 if (mBackBufferRTView)
daniel@transgaming.com32fdf822012-11-28 20:53:30 +000079 {
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +000080 mBackBufferRTView->Release();
81 mBackBufferRTView = NULL;
daniel@transgaming.com32fdf822012-11-28 20:53:30 +000082 }
83
84 if (mOffscreenTexture)
85 {
86 mOffscreenTexture->Release();
87 mOffscreenTexture = NULL;
88 }
89
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +000090 if (mOffscreenRTView)
91 {
92 mOffscreenRTView->Release();
93 mOffscreenRTView = NULL;
94 }
95
daniel@transgaming.come0970472012-11-28 21:05:07 +000096 if (mOffscreenSRView)
97 {
98 mOffscreenSRView->Release();
99 mOffscreenSRView = NULL;
100 }
101
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000102 if (mDepthStencilTexture)
103 {
104 mDepthStencilTexture->Release();
105 mDepthStencilTexture = NULL;
106 }
107
108 if (mDepthStencilDSView)
109 {
110 mDepthStencilDSView->Release();
111 mDepthStencilDSView = NULL;
112 }
113
daniel@transgaming.come0970472012-11-28 21:05:07 +0000114 if (mQuadVB)
115 {
116 mQuadVB->Release();
117 mQuadVB = NULL;
118 }
119
120 if (mPassThroughSampler)
121 {
122 mPassThroughSampler->Release();
123 mPassThroughSampler = NULL;
124 }
125
126 if (mPassThroughIL)
127 {
128 mPassThroughIL->Release();
129 mPassThroughIL = NULL;
130 }
131
132 if (mPassThroughVS)
133 {
134 mPassThroughVS->Release();
135 mPassThroughVS = NULL;
136 }
137
138 if (mPassThroughPS)
139 {
140 mPassThroughPS->Release();
141 mPassThroughPS = NULL;
142 }
143
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000144 if (mWindow)
145 mShareHandle = NULL;
146}
147
148EGLint SwapChain11::reset(int backbufferWidth, int backbufferHeight, EGLint swapInterval)
149{
150 ID3D11Device *device = mRenderer->getDevice();
151
152 if (device == NULL)
153 {
154 return EGL_BAD_ACCESS;
155 }
156
157 // Release specific resources to free up memory for the new render target, while the
158 // old render target still exists for the purpose of preserving its contents.
159 if (mSwapChain)
160 {
161 mSwapChain->Release();
162 mSwapChain = NULL;
163 }
164
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000165 if (mBackBufferTexture)
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000166 {
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000167 mBackBufferTexture->Release();
168 mBackBufferTexture = NULL;
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000169 }
170
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000171 if (mBackBufferRTView)
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000172 {
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000173 mBackBufferRTView->Release();
174 mBackBufferRTView = NULL;
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000175 }
176
177 if (mOffscreenTexture)
178 {
179 mOffscreenTexture->Release();
180 mOffscreenTexture = NULL;
181 }
182
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000183 if (mOffscreenRTView) // TODO: Preserve the render target content
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000184 {
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000185 mOffscreenRTView->Release();
186 mOffscreenRTView = NULL;
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000187 }
188
daniel@transgaming.come0970472012-11-28 21:05:07 +0000189 if (mOffscreenSRView)
190 {
191 mOffscreenSRView->Release();
192 mOffscreenSRView = NULL;
193 }
194
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000195 if (mDepthStencilTexture)
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000196 {
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000197 mDepthStencilTexture->Release();
198 mDepthStencilTexture = NULL;
199 }
200
201 if (mDepthStencilDSView)
202 {
203 mDepthStencilDSView->Release();
204 mDepthStencilDSView = NULL;
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000205 }
206
207 HANDLE *pShareHandle = NULL;
208 if (!mWindow && mRenderer->getShareHandleSupport())
209 {
210 pShareHandle = &mShareHandle;
211 }
212
213 D3D11_TEXTURE2D_DESC offscreenTextureDesc = {0};
214 offscreenTextureDesc.Width = backbufferWidth;
215 offscreenTextureDesc.Height = backbufferHeight;
216 offscreenTextureDesc.Format = gl_d3d11::ConvertRenderbufferFormat(mBackBufferFormat);
217 offscreenTextureDesc.MipLevels = 1;
218 offscreenTextureDesc.ArraySize = 1;
219 offscreenTextureDesc.SampleDesc.Count = 1;
220 offscreenTextureDesc.SampleDesc.Quality = 0;
221 offscreenTextureDesc.Usage = D3D11_USAGE_DEFAULT;
daniel@transgaming.come0970472012-11-28 21:05:07 +0000222 offscreenTextureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000223 offscreenTextureDesc.CPUAccessFlags = 0;
224 offscreenTextureDesc.MiscFlags = 0; // D3D11_RESOURCE_MISC_SHARED
225
226 HRESULT result = device->CreateTexture2D(&offscreenTextureDesc, NULL, &mOffscreenTexture);
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000227 d3d11::SetDebugName(mOffscreenTexture, "Offscreen texture");
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000228
229 if (FAILED(result))
230 {
231 ERR("Could not create offscreen texture: %08lX", result);
232 release();
233
234 if (isDeviceLostError(result))
235 {
236 return EGL_CONTEXT_LOST;
237 }
238 else
239 {
240 return EGL_BAD_ALLOC;
241 }
242 }
243
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000244 result = device->CreateRenderTargetView(mOffscreenTexture, NULL, &mOffscreenRTView);
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000245 ASSERT(SUCCEEDED(result));
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000246 d3d11::SetDebugName(mOffscreenRTView, "Offscreen render target");
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000247
daniel@transgaming.come0970472012-11-28 21:05:07 +0000248 result = device->CreateShaderResourceView(mOffscreenTexture, NULL, &mOffscreenSRView);
249 ASSERT(SUCCEEDED(result));
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000250 d3d11::SetDebugName(mOffscreenSRView, "Offscreen shader resource");
daniel@transgaming.come0970472012-11-28 21:05:07 +0000251
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000252 if (mWindow)
253 {
254 IDXGIFactory *factory = mRenderer->getDxgiFactory();
255
256 DXGI_SWAP_CHAIN_DESC swapChainDesc = {0};
257 swapChainDesc.BufferCount = 2;
258 swapChainDesc.BufferDesc.Format = gl_d3d11::ConvertRenderbufferFormat(mBackBufferFormat);
daniel@transgaming.com567b9cf2012-11-28 21:04:46 +0000259 swapChainDesc.BufferDesc.Width = backbufferWidth;
260 swapChainDesc.BufferDesc.Height = backbufferHeight;
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000261 swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
262 swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
263 swapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
264 swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
265 swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
266 swapChainDesc.Flags = 0;
267 swapChainDesc.OutputWindow = mWindow;
268 swapChainDesc.SampleDesc.Count = 1;
269 swapChainDesc.SampleDesc.Quality = 0;
270 swapChainDesc.Windowed = TRUE;
271
272 result = factory->CreateSwapChain(device, &swapChainDesc, &mSwapChain);
273
274 if (FAILED(result))
275 {
276 ERR("Could not create additional swap chains or offscreen surfaces: %08lX", result);
277 release();
278
279 if (isDeviceLostError(result))
280 {
281 return EGL_CONTEXT_LOST;
282 }
283 else
284 {
285 return EGL_BAD_ALLOC;
286 }
287 }
288
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000289 result = mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&mBackBufferTexture);
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000290 ASSERT(SUCCEEDED(result));
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000291 d3d11::SetDebugName(mBackBufferTexture, "Back buffer texture");
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000292
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000293 result = device->CreateRenderTargetView(mBackBufferTexture, NULL, &mBackBufferRTView);
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000294 ASSERT(SUCCEEDED(result));
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000295 d3d11::SetDebugName(mBackBufferRTView, "Back buffer render target");
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000296 }
297
298 if (mDepthBufferFormat != GL_NONE)
299 {
300 D3D11_TEXTURE2D_DESC depthStencilDesc = {0};
301 depthStencilDesc.Width = backbufferWidth;
302 depthStencilDesc.Height = backbufferHeight;
303 depthStencilDesc.Format = gl_d3d11::ConvertRenderbufferFormat(mDepthBufferFormat);
304 depthStencilDesc.MipLevels = 1;
305 depthStencilDesc.ArraySize = 1;
306 depthStencilDesc.SampleDesc.Count = 1;
307 depthStencilDesc.SampleDesc.Quality = 0;
308 depthStencilDesc.Usage = D3D11_USAGE_DEFAULT;
309 depthStencilDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
310 depthStencilDesc.CPUAccessFlags = 0;
311 depthStencilDesc.MiscFlags = 0;
312
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000313 result = device->CreateTexture2D(&depthStencilDesc, NULL, &mDepthStencilTexture);
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000314 if (FAILED(result))
315 {
316 ERR("Could not create depthstencil surface for new swap chain: 0x%08X", result);
317 release();
318
319 if (isDeviceLostError(result))
320 {
321 return EGL_CONTEXT_LOST;
322 }
323 else
324 {
325 return EGL_BAD_ALLOC;
326 }
327 }
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000328 d3d11::SetDebugName(mDepthStencilTexture, "Depth stencil texture");
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000329
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000330 result = device->CreateDepthStencilView(mDepthStencilTexture, NULL, &mDepthStencilDSView);
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000331 ASSERT(SUCCEEDED(result));
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000332 d3d11::SetDebugName(mDepthStencilDSView, "Depth stencil view");
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000333 }
334
daniel@transgaming.come0970472012-11-28 21:05:07 +0000335 D3D11_BUFFER_DESC vbDesc;
336 vbDesc.ByteWidth = sizeof(QuadVertex) * 4;
337 vbDesc.Usage = D3D11_USAGE_DYNAMIC;
338 vbDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
339 vbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
340 vbDesc.MiscFlags = 0;
341 vbDesc.StructureByteStride = 0;
342
343 result = device->CreateBuffer(&vbDesc, NULL, &mQuadVB);
344 ASSERT(SUCCEEDED(result));
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000345 d3d11::SetDebugName(mQuadVB, "Swap chain quad vertex buffer");
daniel@transgaming.come0970472012-11-28 21:05:07 +0000346
347 D3D11_SAMPLER_DESC samplerDesc;
348 samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
349 samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
350 samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
351 samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
352 samplerDesc.MipLODBias = 0.0f;
353 samplerDesc.MaxAnisotropy = 0;
354 samplerDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
355 samplerDesc.BorderColor[0] = 0.0f;
356 samplerDesc.BorderColor[1] = 0.0f;
357 samplerDesc.BorderColor[2] = 0.0f;
358 samplerDesc.BorderColor[3] = 0.0f;
359 samplerDesc.MinLOD = 0;
360 samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
361
362 result = device->CreateSamplerState(&samplerDesc, &mPassThroughSampler);
363 ASSERT(SUCCEEDED(result));
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000364 d3d11::SetDebugName(mPassThroughSampler, "Swap chain pass through sampler");
daniel@transgaming.come0970472012-11-28 21:05:07 +0000365
366 D3D11_INPUT_ELEMENT_DESC quadLayout[] =
367 {
368 { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
369 { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0 },
370 };
371
372 result = device->CreateInputLayout(quadLayout, 2, g_VS_Passthrough, sizeof(g_VS_Passthrough), &mPassThroughIL);
373 ASSERT(SUCCEEDED(result));
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000374 d3d11::SetDebugName(mPassThroughIL, "Swap chain pass through layout");
daniel@transgaming.come0970472012-11-28 21:05:07 +0000375
376 result = device->CreateVertexShader(g_VS_Passthrough, sizeof(g_VS_Passthrough), NULL, &mPassThroughVS);
377 ASSERT(SUCCEEDED(result));
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000378 d3d11::SetDebugName(mPassThroughVS, "Swap chain pass through vertex shader");
daniel@transgaming.come0970472012-11-28 21:05:07 +0000379
shannon.woods@transgaming.com2570c342013-01-25 21:50:22 +0000380 result = device->CreatePixelShader(g_PS_PassthroughRGBA, sizeof(g_PS_PassthroughRGBA), NULL, &mPassThroughPS);
daniel@transgaming.come0970472012-11-28 21:05:07 +0000381 ASSERT(SUCCEEDED(result));
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000382 d3d11::SetDebugName(mPassThroughPS, "Swap chain pass through pixel shader");
daniel@transgaming.come0970472012-11-28 21:05:07 +0000383
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000384 mWidth = backbufferWidth;
385 mHeight = backbufferHeight;
386
387 return EGL_SUCCESS;
388}
389
390// parameters should be validated/clamped by caller
391EGLint SwapChain11::swapRect(EGLint x, EGLint y, EGLint width, EGLint height)
392{
393 if (!mSwapChain)
394 {
395 return EGL_SUCCESS;
396 }
397
398 ID3D11Device *device = mRenderer->getDevice();
daniel@transgaming.come0970472012-11-28 21:05:07 +0000399 ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000400
daniel@transgaming.come0970472012-11-28 21:05:07 +0000401 // Set vertices
402 D3D11_MAPPED_SUBRESOURCE mappedResource;
403 HRESULT result = deviceContext->Map(mQuadVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
404 if (FAILED(result))
405 {
406 return EGL_BAD_ACCESS;
407 }
408
409 QuadVertex *vertices = static_cast<QuadVertex*>(mappedResource.pData);
410
411 // Create a quad in homogeneous coordinates
412 float x1 = (x / mWidth) * 2.0f - 1.0f;
413 float y1 = ((mHeight - y - height) / mHeight) * 2.0f - 1.0f;
414 float x2 = ((x + width) / mWidth) * 2.0f - 1.0f;
415 float y2 = ((mHeight - y) / mHeight) * 2.0f - 1.0f;
416
417 float u1 = x / float(mWidth);
418 float v1 = y / float(mHeight);
419 float u2 = (x + width) / float(mWidth);
420 float v2 = (y + height) / float(mHeight);
421
422 setVertex(&vertices[0], x1, y1, u1, v1);
423 setVertex(&vertices[1], x1, y2, u1, v2);
424 setVertex(&vertices[2], x2, y1, u2, v1);
425 setVertex(&vertices[3], x2, y2, u2, v2);
426
427 deviceContext->Unmap(mQuadVB, 0);
428
429 static UINT stride = sizeof(QuadVertex);
430 static UINT startIdx = 0;
431 deviceContext->IASetVertexBuffers(0, 1, &mQuadVB, &stride, &startIdx);
432
433 // Apply state
434 deviceContext->OMSetDepthStencilState(NULL, 0xFFFFFFFF);
435
436 static const float blendFactor[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
437 deviceContext->OMSetBlendState(NULL, blendFactor, 0xFFFFFFF);
438
439 deviceContext->RSSetState(NULL);
440
441 // Apply shaders
442 deviceContext->IASetInputLayout(mPassThroughIL);
443 deviceContext->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
444 deviceContext->VSSetShader(mPassThroughVS, NULL, 0);
445 deviceContext->PSSetShader(mPassThroughPS, NULL, 0);
446
447 // Apply render targets
448 deviceContext->OMSetRenderTargets(1, &mBackBufferRTView, NULL);
449
daniel@transgaming.com9799a2f2013-01-11 04:09:27 +0000450 // Set the viewport
451 D3D11_VIEWPORT viewport;
452 viewport.TopLeftX = 0;
453 viewport.TopLeftY = 0;
454 viewport.Width = mWidth;
455 viewport.Height = mHeight;
456 viewport.MinDepth = 0.0f;
457 viewport.MaxDepth = 1.0f;
458 deviceContext->RSSetViewports(1, &viewport);
459
daniel@transgaming.come0970472012-11-28 21:05:07 +0000460 // Apply textures
461 deviceContext->PSSetShaderResources(0, 1, &mOffscreenSRView);
462 deviceContext->PSSetSamplers(0, 1, &mPassThroughSampler);
463
464 // Draw
465 deviceContext->Draw(4, 0);
466 mSwapChain->Present(0, 0);
467
468 // Unbind
469 static ID3D11ShaderResourceView *const nullSRV = NULL;
470 deviceContext->PSSetShaderResources(0, 1, &nullSRV);
471
472 static ID3D11RenderTargetView *const nullRTV = NULL;
473 deviceContext->OMSetRenderTargets(1, &nullRTV, NULL);
474
daniel@transgaming.come0970472012-11-28 21:05:07 +0000475 mRenderer->markAllStateDirty();
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000476
477 return EGL_SUCCESS;
478}
479
shannon.woods@transgaming.com5c25ed22013-01-25 21:49:51 +0000480// Increments refcount on texture.
481// caller must Release() the returned texture
482ID3D11Texture2D *SwapChain11::getOffscreenTexture()
483{
484 if (mOffscreenTexture)
485 {
486 mOffscreenTexture->AddRef();
487 }
488
489 return mOffscreenTexture;
490}
491
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000492// Increments refcount on view.
493// caller must Release() the returned view
494ID3D11RenderTargetView *SwapChain11::getRenderTarget()
495{
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000496 if (mOffscreenRTView)
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000497 {
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000498 mOffscreenRTView->AddRef();
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000499 }
500
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000501 return mOffscreenRTView;
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000502}
503
504// Increments refcount on view.
505// caller must Release() the returned view
shannon.woods@transgaming.com5c25ed22013-01-25 21:49:51 +0000506ID3D11ShaderResourceView *SwapChain11::getRenderTargetShaderResource()
507{
508 if (mOffscreenSRView)
509 {
510 mOffscreenSRView->AddRef();
511 }
512
513 return mOffscreenSRView;
514}
515
516// Increments refcount on view.
517// caller must Release() the returned view
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000518ID3D11DepthStencilView *SwapChain11::getDepthStencil()
519{
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000520 if (mDepthStencilDSView)
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000521 {
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000522 mDepthStencilDSView->AddRef();
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000523 }
524
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000525 return mDepthStencilDSView;
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000526}
527
daniel@transgaming.comd733bb82012-11-28 20:53:40 +0000528SwapChain11 *SwapChain11::makeSwapChain11(SwapChain *swapChain)
529{
530 ASSERT(dynamic_cast<rx::SwapChain11*>(swapChain) != NULL);
531 return static_cast<rx::SwapChain11*>(swapChain);
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000532}
daniel@transgaming.comd733bb82012-11-28 20:53:40 +0000533
534}