blob: cf2714292134e671f6c7e7da8259b37e9c07f1f0 [file] [log] [blame]
daniel@transgaming.com32fdf822012-11-28 20:53:30 +00001//
2// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
3// 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"
19#include "libGLESv2/renderer/shaders/compiled/passthrough11ps.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.com32fdf822012-11-28 20:53:30 +000050 mWidth = -1;
51 mHeight = -1;
52}
53
54SwapChain11::~SwapChain11()
55{
56 release();
57}
58
59void SwapChain11::release()
60{
61 if (mSwapChain)
62 {
63 mSwapChain->Release();
64 mSwapChain = NULL;
65 }
66
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +000067 if (mBackBufferTexture)
daniel@transgaming.com32fdf822012-11-28 20:53:30 +000068 {
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +000069 mBackBufferTexture->Release();
70 mBackBufferTexture = NULL;
daniel@transgaming.com32fdf822012-11-28 20:53:30 +000071 }
72
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +000073 if (mBackBufferRTView)
daniel@transgaming.com32fdf822012-11-28 20:53:30 +000074 {
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +000075 mBackBufferRTView->Release();
76 mBackBufferRTView = NULL;
daniel@transgaming.com32fdf822012-11-28 20:53:30 +000077 }
78
79 if (mOffscreenTexture)
80 {
81 mOffscreenTexture->Release();
82 mOffscreenTexture = NULL;
83 }
84
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +000085 if (mOffscreenRTView)
86 {
87 mOffscreenRTView->Release();
88 mOffscreenRTView = NULL;
89 }
90
daniel@transgaming.come0970472012-11-28 21:05:07 +000091 if (mOffscreenSRView)
92 {
93 mOffscreenSRView->Release();
94 mOffscreenSRView = NULL;
95 }
96
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +000097 if (mDepthStencilTexture)
98 {
99 mDepthStencilTexture->Release();
100 mDepthStencilTexture = NULL;
101 }
102
103 if (mDepthStencilDSView)
104 {
105 mDepthStencilDSView->Release();
106 mDepthStencilDSView = NULL;
107 }
108
daniel@transgaming.come0970472012-11-28 21:05:07 +0000109 if (mQuadVB)
110 {
111 mQuadVB->Release();
112 mQuadVB = NULL;
113 }
114
115 if (mPassThroughSampler)
116 {
117 mPassThroughSampler->Release();
118 mPassThroughSampler = NULL;
119 }
120
121 if (mPassThroughIL)
122 {
123 mPassThroughIL->Release();
124 mPassThroughIL = NULL;
125 }
126
127 if (mPassThroughVS)
128 {
129 mPassThroughVS->Release();
130 mPassThroughVS = NULL;
131 }
132
133 if (mPassThroughPS)
134 {
135 mPassThroughPS->Release();
136 mPassThroughPS = NULL;
137 }
138
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000139 if (mWindow)
140 mShareHandle = NULL;
141}
142
143EGLint SwapChain11::reset(int backbufferWidth, int backbufferHeight, EGLint swapInterval)
144{
145 ID3D11Device *device = mRenderer->getDevice();
146
147 if (device == NULL)
148 {
149 return EGL_BAD_ACCESS;
150 }
151
152 // Release specific resources to free up memory for the new render target, while the
153 // old render target still exists for the purpose of preserving its contents.
154 if (mSwapChain)
155 {
156 mSwapChain->Release();
157 mSwapChain = NULL;
158 }
159
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000160 if (mBackBufferTexture)
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000161 {
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000162 mBackBufferTexture->Release();
163 mBackBufferTexture = NULL;
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000164 }
165
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000166 if (mBackBufferRTView)
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000167 {
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000168 mBackBufferRTView->Release();
169 mBackBufferRTView = NULL;
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000170 }
171
172 if (mOffscreenTexture)
173 {
174 mOffscreenTexture->Release();
175 mOffscreenTexture = NULL;
176 }
177
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000178 if (mOffscreenRTView) // TODO: Preserve the render target content
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000179 {
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000180 mOffscreenRTView->Release();
181 mOffscreenRTView = NULL;
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000182 }
183
daniel@transgaming.come0970472012-11-28 21:05:07 +0000184 if (mOffscreenSRView)
185 {
186 mOffscreenSRView->Release();
187 mOffscreenSRView = NULL;
188 }
189
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000190 if (mDepthStencilTexture)
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000191 {
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000192 mDepthStencilTexture->Release();
193 mDepthStencilTexture = NULL;
194 }
195
196 if (mDepthStencilDSView)
197 {
198 mDepthStencilDSView->Release();
199 mDepthStencilDSView = NULL;
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000200 }
201
202 HANDLE *pShareHandle = NULL;
203 if (!mWindow && mRenderer->getShareHandleSupport())
204 {
205 pShareHandle = &mShareHandle;
206 }
207
208 D3D11_TEXTURE2D_DESC offscreenTextureDesc = {0};
209 offscreenTextureDesc.Width = backbufferWidth;
210 offscreenTextureDesc.Height = backbufferHeight;
211 offscreenTextureDesc.Format = gl_d3d11::ConvertRenderbufferFormat(mBackBufferFormat);
212 offscreenTextureDesc.MipLevels = 1;
213 offscreenTextureDesc.ArraySize = 1;
214 offscreenTextureDesc.SampleDesc.Count = 1;
215 offscreenTextureDesc.SampleDesc.Quality = 0;
216 offscreenTextureDesc.Usage = D3D11_USAGE_DEFAULT;
daniel@transgaming.come0970472012-11-28 21:05:07 +0000217 offscreenTextureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000218 offscreenTextureDesc.CPUAccessFlags = 0;
219 offscreenTextureDesc.MiscFlags = 0; // D3D11_RESOURCE_MISC_SHARED
220
221 HRESULT result = device->CreateTexture2D(&offscreenTextureDesc, NULL, &mOffscreenTexture);
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000222 d3d11::SetDebugName(mOffscreenTexture, "Offscreen texture");
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000223
224 if (FAILED(result))
225 {
226 ERR("Could not create offscreen texture: %08lX", result);
227 release();
228
229 if (isDeviceLostError(result))
230 {
231 return EGL_CONTEXT_LOST;
232 }
233 else
234 {
235 return EGL_BAD_ALLOC;
236 }
237 }
238
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000239 result = device->CreateRenderTargetView(mOffscreenTexture, NULL, &mOffscreenRTView);
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000240 ASSERT(SUCCEEDED(result));
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000241 d3d11::SetDebugName(mOffscreenRTView, "Offscreen render target");
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000242
daniel@transgaming.come0970472012-11-28 21:05:07 +0000243 result = device->CreateShaderResourceView(mOffscreenTexture, NULL, &mOffscreenSRView);
244 ASSERT(SUCCEEDED(result));
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000245 d3d11::SetDebugName(mOffscreenSRView, "Offscreen shader resource");
daniel@transgaming.come0970472012-11-28 21:05:07 +0000246
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000247 if (mWindow)
248 {
249 IDXGIFactory *factory = mRenderer->getDxgiFactory();
250
251 DXGI_SWAP_CHAIN_DESC swapChainDesc = {0};
252 swapChainDesc.BufferCount = 2;
253 swapChainDesc.BufferDesc.Format = gl_d3d11::ConvertRenderbufferFormat(mBackBufferFormat);
daniel@transgaming.com567b9cf2012-11-28 21:04:46 +0000254 swapChainDesc.BufferDesc.Width = backbufferWidth;
255 swapChainDesc.BufferDesc.Height = backbufferHeight;
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000256 swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
257 swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
258 swapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
259 swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
260 swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
261 swapChainDesc.Flags = 0;
262 swapChainDesc.OutputWindow = mWindow;
263 swapChainDesc.SampleDesc.Count = 1;
264 swapChainDesc.SampleDesc.Quality = 0;
265 swapChainDesc.Windowed = TRUE;
266
267 result = factory->CreateSwapChain(device, &swapChainDesc, &mSwapChain);
268
269 if (FAILED(result))
270 {
271 ERR("Could not create additional swap chains or offscreen surfaces: %08lX", result);
272 release();
273
274 if (isDeviceLostError(result))
275 {
276 return EGL_CONTEXT_LOST;
277 }
278 else
279 {
280 return EGL_BAD_ALLOC;
281 }
282 }
283
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000284 result = mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&mBackBufferTexture);
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000285 ASSERT(SUCCEEDED(result));
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000286 d3d11::SetDebugName(mBackBufferTexture, "Back buffer texture");
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000287
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000288 result = device->CreateRenderTargetView(mBackBufferTexture, NULL, &mBackBufferRTView);
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000289 ASSERT(SUCCEEDED(result));
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000290 d3d11::SetDebugName(mBackBufferRTView, "Back buffer render target");
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000291 }
292
293 if (mDepthBufferFormat != GL_NONE)
294 {
295 D3D11_TEXTURE2D_DESC depthStencilDesc = {0};
296 depthStencilDesc.Width = backbufferWidth;
297 depthStencilDesc.Height = backbufferHeight;
298 depthStencilDesc.Format = gl_d3d11::ConvertRenderbufferFormat(mDepthBufferFormat);
299 depthStencilDesc.MipLevels = 1;
300 depthStencilDesc.ArraySize = 1;
301 depthStencilDesc.SampleDesc.Count = 1;
302 depthStencilDesc.SampleDesc.Quality = 0;
303 depthStencilDesc.Usage = D3D11_USAGE_DEFAULT;
304 depthStencilDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
305 depthStencilDesc.CPUAccessFlags = 0;
306 depthStencilDesc.MiscFlags = 0;
307
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000308 result = device->CreateTexture2D(&depthStencilDesc, NULL, &mDepthStencilTexture);
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000309 if (FAILED(result))
310 {
311 ERR("Could not create depthstencil surface for new swap chain: 0x%08X", result);
312 release();
313
314 if (isDeviceLostError(result))
315 {
316 return EGL_CONTEXT_LOST;
317 }
318 else
319 {
320 return EGL_BAD_ALLOC;
321 }
322 }
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000323 d3d11::SetDebugName(mDepthStencilTexture, "Depth stencil texture");
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000324
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000325 result = device->CreateDepthStencilView(mDepthStencilTexture, NULL, &mDepthStencilDSView);
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000326 ASSERT(SUCCEEDED(result));
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000327 d3d11::SetDebugName(mDepthStencilDSView, "Depth stencil view");
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000328 }
329
daniel@transgaming.come0970472012-11-28 21:05:07 +0000330 D3D11_BUFFER_DESC vbDesc;
331 vbDesc.ByteWidth = sizeof(QuadVertex) * 4;
332 vbDesc.Usage = D3D11_USAGE_DYNAMIC;
333 vbDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
334 vbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
335 vbDesc.MiscFlags = 0;
336 vbDesc.StructureByteStride = 0;
337
338 result = device->CreateBuffer(&vbDesc, NULL, &mQuadVB);
339 ASSERT(SUCCEEDED(result));
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000340 d3d11::SetDebugName(mQuadVB, "Swap chain quad vertex buffer");
daniel@transgaming.come0970472012-11-28 21:05:07 +0000341
342 D3D11_SAMPLER_DESC samplerDesc;
343 samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
344 samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
345 samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
346 samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
347 samplerDesc.MipLODBias = 0.0f;
348 samplerDesc.MaxAnisotropy = 0;
349 samplerDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
350 samplerDesc.BorderColor[0] = 0.0f;
351 samplerDesc.BorderColor[1] = 0.0f;
352 samplerDesc.BorderColor[2] = 0.0f;
353 samplerDesc.BorderColor[3] = 0.0f;
354 samplerDesc.MinLOD = 0;
355 samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
356
357 result = device->CreateSamplerState(&samplerDesc, &mPassThroughSampler);
358 ASSERT(SUCCEEDED(result));
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000359 d3d11::SetDebugName(mPassThroughSampler, "Swap chain pass through sampler");
daniel@transgaming.come0970472012-11-28 21:05:07 +0000360
361 D3D11_INPUT_ELEMENT_DESC quadLayout[] =
362 {
363 { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
364 { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0 },
365 };
366
367 result = device->CreateInputLayout(quadLayout, 2, g_VS_Passthrough, sizeof(g_VS_Passthrough), &mPassThroughIL);
368 ASSERT(SUCCEEDED(result));
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000369 d3d11::SetDebugName(mPassThroughIL, "Swap chain pass through layout");
daniel@transgaming.come0970472012-11-28 21:05:07 +0000370
371 result = device->CreateVertexShader(g_VS_Passthrough, sizeof(g_VS_Passthrough), NULL, &mPassThroughVS);
372 ASSERT(SUCCEEDED(result));
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000373 d3d11::SetDebugName(mPassThroughVS, "Swap chain pass through vertex shader");
daniel@transgaming.come0970472012-11-28 21:05:07 +0000374
375 result = device->CreatePixelShader(g_PS_Passthrough, sizeof(g_PS_Passthrough), NULL, &mPassThroughPS);
376 ASSERT(SUCCEEDED(result));
daniel@transgaming.comad3d8272013-01-11 04:11:14 +0000377 d3d11::SetDebugName(mPassThroughPS, "Swap chain pass through pixel shader");
daniel@transgaming.come0970472012-11-28 21:05:07 +0000378
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000379 mWidth = backbufferWidth;
380 mHeight = backbufferHeight;
381
382 return EGL_SUCCESS;
383}
384
385// parameters should be validated/clamped by caller
386EGLint SwapChain11::swapRect(EGLint x, EGLint y, EGLint width, EGLint height)
387{
388 if (!mSwapChain)
389 {
390 return EGL_SUCCESS;
391 }
392
393 ID3D11Device *device = mRenderer->getDevice();
daniel@transgaming.come0970472012-11-28 21:05:07 +0000394 ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000395
daniel@transgaming.come0970472012-11-28 21:05:07 +0000396 // Set vertices
397 D3D11_MAPPED_SUBRESOURCE mappedResource;
398 HRESULT result = deviceContext->Map(mQuadVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
399 if (FAILED(result))
400 {
401 return EGL_BAD_ACCESS;
402 }
403
404 QuadVertex *vertices = static_cast<QuadVertex*>(mappedResource.pData);
405
406 // Create a quad in homogeneous coordinates
407 float x1 = (x / mWidth) * 2.0f - 1.0f;
408 float y1 = ((mHeight - y - height) / mHeight) * 2.0f - 1.0f;
409 float x2 = ((x + width) / mWidth) * 2.0f - 1.0f;
410 float y2 = ((mHeight - y) / mHeight) * 2.0f - 1.0f;
411
412 float u1 = x / float(mWidth);
413 float v1 = y / float(mHeight);
414 float u2 = (x + width) / float(mWidth);
415 float v2 = (y + height) / float(mHeight);
416
417 setVertex(&vertices[0], x1, y1, u1, v1);
418 setVertex(&vertices[1], x1, y2, u1, v2);
419 setVertex(&vertices[2], x2, y1, u2, v1);
420 setVertex(&vertices[3], x2, y2, u2, v2);
421
422 deviceContext->Unmap(mQuadVB, 0);
423
424 static UINT stride = sizeof(QuadVertex);
425 static UINT startIdx = 0;
426 deviceContext->IASetVertexBuffers(0, 1, &mQuadVB, &stride, &startIdx);
427
428 // Apply state
429 deviceContext->OMSetDepthStencilState(NULL, 0xFFFFFFFF);
430
431 static const float blendFactor[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
432 deviceContext->OMSetBlendState(NULL, blendFactor, 0xFFFFFFF);
433
434 deviceContext->RSSetState(NULL);
435
436 // Apply shaders
437 deviceContext->IASetInputLayout(mPassThroughIL);
438 deviceContext->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
439 deviceContext->VSSetShader(mPassThroughVS, NULL, 0);
440 deviceContext->PSSetShader(mPassThroughPS, NULL, 0);
441
442 // Apply render targets
443 deviceContext->OMSetRenderTargets(1, &mBackBufferRTView, NULL);
444
daniel@transgaming.com9799a2f2013-01-11 04:09:27 +0000445 // Set the viewport
446 D3D11_VIEWPORT viewport;
447 viewport.TopLeftX = 0;
448 viewport.TopLeftY = 0;
449 viewport.Width = mWidth;
450 viewport.Height = mHeight;
451 viewport.MinDepth = 0.0f;
452 viewport.MaxDepth = 1.0f;
453 deviceContext->RSSetViewports(1, &viewport);
454
daniel@transgaming.come0970472012-11-28 21:05:07 +0000455 // Apply textures
456 deviceContext->PSSetShaderResources(0, 1, &mOffscreenSRView);
457 deviceContext->PSSetSamplers(0, 1, &mPassThroughSampler);
458
459 // Draw
460 deviceContext->Draw(4, 0);
461 mSwapChain->Present(0, 0);
462
463 // Unbind
464 static ID3D11ShaderResourceView *const nullSRV = NULL;
465 deviceContext->PSSetShaderResources(0, 1, &nullSRV);
466
467 static ID3D11RenderTargetView *const nullRTV = NULL;
468 deviceContext->OMSetRenderTargets(1, &nullRTV, NULL);
469
470 // Mark context and renderer dirty flags
471 gl::Context *glContext = static_cast<gl::Context*>(glGetCurrentContext());
472 if (glContext)
473 {
474 glContext->markAllStateDirty();
475 }
476 mRenderer->markAllStateDirty();
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000477
478 return EGL_SUCCESS;
479}
480
481// Increments refcount on view.
482// caller must Release() the returned view
483ID3D11RenderTargetView *SwapChain11::getRenderTarget()
484{
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000485 if (mOffscreenRTView)
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000486 {
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000487 mOffscreenRTView->AddRef();
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000488 }
489
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000490 return mOffscreenRTView;
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000491}
492
493// Increments refcount on view.
494// caller must Release() the returned view
495ID3D11DepthStencilView *SwapChain11::getDepthStencil()
496{
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000497 if (mDepthStencilDSView)
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000498 {
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000499 mDepthStencilDSView->AddRef();
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000500 }
501
daniel@transgaming.comc8c70ad2012-11-28 21:04:37 +0000502 return mDepthStencilDSView;
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000503}
504
505// Increments refcount on texture.
506// caller must Release() the returned texture
507ID3D11Texture2D *SwapChain11::getOffscreenTexture()
508{
509 if (mOffscreenTexture)
510 {
511 mOffscreenTexture->AddRef();
512 }
513
514 return mOffscreenTexture;
515}
516
daniel@transgaming.comd733bb82012-11-28 20:53:40 +0000517SwapChain11 *SwapChain11::makeSwapChain11(SwapChain *swapChain)
518{
519 ASSERT(dynamic_cast<rx::SwapChain11*>(swapChain) != NULL);
520 return static_cast<rx::SwapChain11*>(swapChain);
daniel@transgaming.com32fdf822012-11-28 20:53:30 +0000521}
daniel@transgaming.comd733bb82012-11-28 20:53:40 +0000522
523}
524