blob: 43a3a047cc7a8af40eeee287f143752fc3db38d7 [file] [log] [blame]
daniel@transgaming.com4834ee22013-01-11 04:06:16 +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// TextureStorage11.cpp: Implements the abstract rx::TextureStorage11 class and its concrete derived
8// classes TextureStorage11_2D and TextureStorage11_Cube, which act as the interface to the D3D11 texture.
9
10#include "libGLESv2/renderer/TextureStorage11.h"
11
12#include "libGLESv2/renderer/Renderer11.h"
13#include "libGLESv2/renderer/RenderTarget11.h"
14#include "libGLESv2/renderer/SwapChain11.h"
15#include "libGLESv2/renderer/renderer11_utils.h"
16
17#include "libGLESv2/main.h"
18
19namespace rx
20{
21
22TextureStorage11::TextureStorage11(Renderer *renderer, UINT bindFlags)
23 : mBindFlags(bindFlags),
daniel@transgaming.comb1154552013-01-11 04:11:02 +000024 mLodOffset(0),
25 mMipLevels(0)
daniel@transgaming.com4834ee22013-01-11 04:06:16 +000026{
27 mRenderer = Renderer11::makeRenderer11(renderer);
28}
29
30TextureStorage11::~TextureStorage11()
31{
daniel@transgaming.com1e1b5e92013-01-11 04:11:27 +000032}
daniel@transgaming.com4834ee22013-01-11 04:06:16 +000033
34TextureStorage11 *TextureStorage11::makeTextureStorage11(TextureStorage *storage)
35{
36 ASSERT(dynamic_cast<TextureStorage11*>(storage) != NULL);
37 return static_cast<TextureStorage11*>(storage);
38}
39
40DWORD TextureStorage11::GetTextureBindFlags(DXGI_FORMAT format, GLenum glusage, bool forceRenderable)
41{
42 UINT bindFlags = D3D11_BIND_SHADER_RESOURCE;
43
44 if (format == DXGI_FORMAT_D24_UNORM_S8_UINT)
45 {
46 bindFlags |= D3D11_BIND_DEPTH_STENCIL;
47 }
48 else if(forceRenderable || (TextureStorage11::IsTextureFormatRenderable(format) && (glusage == GL_FRAMEBUFFER_ATTACHMENT_ANGLE)))
49 {
50 bindFlags |= D3D11_BIND_RENDER_TARGET;
51 }
52 return bindFlags;
53}
54
55bool TextureStorage11::IsTextureFormatRenderable(DXGI_FORMAT format)
56{
57 switch(format)
58 {
59 case DXGI_FORMAT_R8G8B8A8_UNORM:
60 case DXGI_FORMAT_A8_UNORM:
61 case DXGI_FORMAT_R32G32B32A32_FLOAT:
62 case DXGI_FORMAT_R32G32B32_FLOAT:
63 case DXGI_FORMAT_R16G16B16A16_FLOAT:
64 case DXGI_FORMAT_B8G8R8A8_UNORM:
65 case DXGI_FORMAT_R8_UNORM:
66 case DXGI_FORMAT_R8G8_UNORM:
67 case DXGI_FORMAT_R16_FLOAT:
68 case DXGI_FORMAT_R16G16_FLOAT:
69 return true;
70 case DXGI_FORMAT_BC1_UNORM:
71 case DXGI_FORMAT_BC2_UNORM:
72 case DXGI_FORMAT_BC3_UNORM:
73 return false;
74 default:
75 UNREACHABLE();
76 return false;
77 }
78}
79
80UINT TextureStorage11::getBindFlags() const
81{
82 return mBindFlags;
83}
84
85int TextureStorage11::getLodOffset() const
86{
87 return mLodOffset;
88}
89
90bool TextureStorage11::isRenderTarget() const
91{
92 return (mBindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_DEPTH_STENCIL)) != 0;
93}
94
95bool TextureStorage11::isManaged() const
96{
97 return false;
98}
99
daniel@transgaming.com4834ee22013-01-11 04:06:16 +0000100int TextureStorage11::levelCount()
101{
102 int levels = 0;
103 if (getBaseTexture())
104 {
daniel@transgaming.comb1154552013-01-11 04:11:02 +0000105 levels = mMipLevels - getLodOffset();
daniel@transgaming.com4834ee22013-01-11 04:06:16 +0000106 }
107 return levels;
108}
109
daniel@transgaming.com9a2f54d2013-01-11 04:06:36 +0000110UINT TextureStorage11::getSubresourceIndex(int level, int faceIndex)
111{
112 UINT index = 0;
113 if (getBaseTexture())
114 {
daniel@transgaming.comb1154552013-01-11 04:11:02 +0000115 index = D3D11CalcSubresource(level, faceIndex, mMipLevels);
daniel@transgaming.com9a2f54d2013-01-11 04:06:36 +0000116 }
117 return index;
118}
119
120bool TextureStorage11::updateSubresourceLevel(ID3D11Texture2D *srcTexture, int level, int face, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height)
121{
122 if (srcTexture)
123 {
124 D3D11_BOX srcBox;
125 srcBox.left = xoffset;
126 srcBox.top = yoffset;
127 srcBox.right = xoffset + width;
128 srcBox.bottom = yoffset + height;
129 srcBox.front = 0;
130 srcBox.back = 1;
131
132 ID3D11DeviceContext *context = mRenderer->getDeviceContext();
133
shannon.woods@transgaming.com858d32f2013-01-25 21:49:59 +0000134 ASSERT(getBaseTexture());
daniel@transgaming.com9a2f54d2013-01-11 04:06:36 +0000135 context->CopySubresourceRegion(getBaseTexture(), getSubresourceIndex(level, face), xoffset, yoffset, 0, srcTexture, 0, &srcBox);
136 return true;
137 }
138
139 return false;
140}
141
daniel@transgaming.com4834ee22013-01-11 04:06:16 +0000142TextureStorage11_2D::TextureStorage11_2D(Renderer *renderer, SwapChain11 *swapchain)
143 : TextureStorage11(renderer, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE)
144{
145 ID3D11Texture2D *surfaceTexture = swapchain->getOffscreenTexture();
146 mTexture = surfaceTexture;
daniel@transgaming.comb50d5302013-01-11 04:07:29 +0000147 mSRV = NULL;
shannon.woods@transgaming.com858d32f2013-01-25 21:49:59 +0000148
149 for (unsigned int i = 0; i < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS; i++)
150 {
151 mRenderTarget[i] = NULL;
152 }
daniel@transgaming.com4834ee22013-01-11 04:06:16 +0000153
154 D3D11_TEXTURE2D_DESC desc;
155 surfaceTexture->GetDesc(&desc);
156
daniel@transgaming.comb1154552013-01-11 04:11:02 +0000157 mMipLevels = desc.MipLevels;
shannon.woods@transgaming.com858d32f2013-01-25 21:49:59 +0000158 mTextureFormat = desc.Format;
159 mTextureWidth = desc.Width;
160 mTextureHeight = desc.Height;
daniel@transgaming.com4834ee22013-01-11 04:06:16 +0000161}
162
163TextureStorage11_2D::TextureStorage11_2D(Renderer *renderer, int levels, GLenum internalformat, GLenum usage, bool forceRenderable, GLsizei width, GLsizei height)
164 : TextureStorage11(renderer, GetTextureBindFlags(gl_d3d11::ConvertTextureFormat(internalformat), usage, forceRenderable))
165{
166 mTexture = NULL;
daniel@transgaming.comb50d5302013-01-11 04:07:29 +0000167 mSRV = NULL;
shannon.woods@transgaming.com858d32f2013-01-25 21:49:59 +0000168 mTextureWidth = 0;
169 mTextureHeight = 0;
daniel@transgaming.com4834ee22013-01-11 04:06:16 +0000170 DXGI_FORMAT format = gl_d3d11::ConvertTextureFormat(internalformat);
daniel@transgaming.comb1154552013-01-11 04:11:02 +0000171
shannon.woods@transgaming.com858d32f2013-01-25 21:49:59 +0000172 for (unsigned int i = 0; i < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS; i++)
173 {
174 mRenderTarget[i] = NULL;
175 }
176
daniel@transgaming.com4834ee22013-01-11 04:06:16 +0000177 // if the width or height is not positive this should be treated as an incomplete texture
178 // we handle that here by skipping the d3d texture creation
179 if (width > 0 && height > 0)
180 {
181 // adjust size if needed for compressed textures
182 gl::MakeValidSize(false, gl::IsCompressed(internalformat), &width, &height, &mLodOffset);
183
184 ID3D11Device *device = mRenderer->getDevice();
185
186 D3D11_TEXTURE2D_DESC desc;
187 desc.Width = width; // Compressed texture size constraints?
188 desc.Height = height;
189 desc.MipLevels = levels + mLodOffset;
190 desc.ArraySize = 1;
191 desc.Format = format;
192 desc.SampleDesc.Count = 1;
193 desc.SampleDesc.Quality = 0;
194 desc.Usage = D3D11_USAGE_DEFAULT;
195 desc.BindFlags = getBindFlags();
196 desc.CPUAccessFlags = 0;
197 desc.MiscFlags = 0;
198
199 HRESULT result = device->CreateTexture2D(&desc, NULL, &mTexture);
200
201 if (FAILED(result))
202 {
203 ASSERT(result == E_OUTOFMEMORY);
204 ERR("Creating image failed.");
205 error(GL_OUT_OF_MEMORY);
206 }
daniel@transgaming.comb1154552013-01-11 04:11:02 +0000207 else
208 {
209 mTexture->GetDesc(&desc);
210 mMipLevels = desc.MipLevels;
shannon.woods@transgaming.com858d32f2013-01-25 21:49:59 +0000211 mTextureFormat = desc.Format;
212 mTextureWidth = desc.Width;
213 mTextureHeight = desc.Height;
daniel@transgaming.comb1154552013-01-11 04:11:02 +0000214 }
daniel@transgaming.com4834ee22013-01-11 04:06:16 +0000215 }
daniel@transgaming.com4834ee22013-01-11 04:06:16 +0000216}
217
218TextureStorage11_2D::~TextureStorage11_2D()
219{
220 if (mTexture)
shannon.woods@transgaming.com4b472352013-01-25 21:14:56 +0000221 {
daniel@transgaming.com4834ee22013-01-11 04:06:16 +0000222 mTexture->Release();
shannon.woods@transgaming.com4b472352013-01-25 21:14:56 +0000223 mTexture = NULL;
224 }
daniel@transgaming.com1e1b5e92013-01-11 04:11:27 +0000225
226 if (mSRV)
shannon.woods@transgaming.com4b472352013-01-25 21:14:56 +0000227 {
daniel@transgaming.com1e1b5e92013-01-11 04:11:27 +0000228 mSRV->Release();
shannon.woods@transgaming.com4b472352013-01-25 21:14:56 +0000229 mSRV = NULL;
230 }
231
shannon.woods@transgaming.com858d32f2013-01-25 21:49:59 +0000232 for (unsigned int i = 0; i < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS; i++)
shannon.woods@transgaming.com4b472352013-01-25 21:14:56 +0000233 {
shannon.woods@transgaming.com858d32f2013-01-25 21:49:59 +0000234 delete mRenderTarget[i];
235 mRenderTarget[i] = NULL;
shannon.woods@transgaming.com4b472352013-01-25 21:14:56 +0000236 }
daniel@transgaming.com4834ee22013-01-11 04:06:16 +0000237}
238
239TextureStorage11_2D *TextureStorage11_2D::makeTextureStorage11_2D(TextureStorage *storage)
240{
241 ASSERT(dynamic_cast<TextureStorage11_2D*>(storage) != NULL);
242 return static_cast<TextureStorage11_2D*>(storage);
243}
244
shannon.woods@transgaming.com858d32f2013-01-25 21:49:59 +0000245RenderTarget *TextureStorage11_2D::getRenderTarget(int level)
daniel@transgaming.com4834ee22013-01-11 04:06:16 +0000246{
shannon.woods@transgaming.com858d32f2013-01-25 21:49:59 +0000247 if (level >= 0 && level < static_cast<int>(mMipLevels))
shannon.woods@transgaming.com4b472352013-01-25 21:14:56 +0000248 {
shannon.woods@transgaming.com858d32f2013-01-25 21:49:59 +0000249 if (!mRenderTarget[level])
250 {
251 ID3D11Device *device = mRenderer->getDevice();
252 HRESULT result;
253
254 D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
255 rtvDesc.Format = mTextureFormat;
256 rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
257 rtvDesc.Texture2D.MipSlice = level;
258
259 ID3D11RenderTargetView *rtv;
260 result = device->CreateRenderTargetView(mTexture, &rtvDesc, &rtv);
261
262 if (result == E_OUTOFMEMORY)
263 {
264 return error(GL_OUT_OF_MEMORY, static_cast<RenderTarget*>(NULL));
265 }
266 ASSERT(SUCCEEDED(result));
267
shannon.woods@transgaming.com183408d2013-01-25 21:50:07 +0000268 D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
269 srvDesc.Format = mTextureFormat;
270 srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
271 srvDesc.Texture2D.MostDetailedMip = level;
272 srvDesc.Texture2D.MipLevels = 1;
273
274 ID3D11ShaderResourceView *srv;
275 result = device->CreateShaderResourceView(mTexture, &srvDesc, &srv);
276
277 if (result == E_OUTOFMEMORY)
278 {
279 rtv->Release();
280 return error(GL_OUT_OF_MEMORY, static_cast<RenderTarget*>(NULL));
281 }
282 ASSERT(SUCCEEDED(result));
283
284 mRenderTarget[level] = new RenderTarget11(mRenderer, rtv, srv,
shannon.woods@transgaming.com858d32f2013-01-25 21:49:59 +0000285 std::max(mTextureWidth >> level, 1U),
286 std::max(mTextureHeight >> level, 1U));
287 }
288
289 return mRenderTarget[level];
shannon.woods@transgaming.com4b472352013-01-25 21:14:56 +0000290 }
291 else
292 {
shannon.woods@transgaming.com858d32f2013-01-25 21:49:59 +0000293 return NULL;
shannon.woods@transgaming.com4b472352013-01-25 21:14:56 +0000294 }
daniel@transgaming.com4834ee22013-01-11 04:06:16 +0000295}
296
297ID3D11Texture2D *TextureStorage11_2D::getBaseTexture() const
298{
299 return mTexture;
300}
301
shannon.woods@transgaming.com858d32f2013-01-25 21:49:59 +0000302ID3D11ShaderResourceView *TextureStorage11_2D::getSRV()
daniel@transgaming.comb50d5302013-01-11 04:07:29 +0000303{
shannon.woods@transgaming.com858d32f2013-01-25 21:49:59 +0000304 if (!mSRV)
305 {
306 ID3D11Device *device = mRenderer->getDevice();
307
308 D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
309 srvDesc.Format = mTextureFormat;
310 srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
311 srvDesc.Texture2D.MipLevels = (mMipLevels == 0 ? -1 : mMipLevels);
312 srvDesc.Texture2D.MostDetailedMip = 0;
313
314 HRESULT result = device->CreateShaderResourceView(mTexture, &srvDesc, &mSRV);
315
316 if (result == E_OUTOFMEMORY)
317 {
318 return error(GL_OUT_OF_MEMORY, static_cast<ID3D11ShaderResourceView*>(NULL));
319 }
320 ASSERT(SUCCEEDED(result));
321 }
322
daniel@transgaming.comb50d5302013-01-11 04:07:29 +0000323 return mSRV;
324}
325
daniel@transgaming.com4834ee22013-01-11 04:06:16 +0000326void TextureStorage11_2D::generateMipmap(int level)
327{
328 // TODO
329 UNIMPLEMENTED();
330}
331
daniel@transgaming.comb2151e52013-01-11 04:06:24 +0000332TextureStorage11_Cube::TextureStorage11_Cube(Renderer *renderer, int levels, GLenum internalformat, GLenum usage, bool forceRenderable, int size)
333 : TextureStorage11(renderer, GetTextureBindFlags(gl_d3d11::ConvertTextureFormat(internalformat), usage, forceRenderable))
334{
335 mTexture = NULL;
daniel@transgaming.comb50d5302013-01-11 04:07:29 +0000336 mSRV = NULL;
shannon.woods@transgaming.com858d32f2013-01-25 21:49:59 +0000337 mTextureWidth = 0;
338 mTextureHeight = 0;
shannon.woods@transgaming.com4b472352013-01-25 21:14:56 +0000339
shannon.woods@transgaming.com858d32f2013-01-25 21:49:59 +0000340 for (unsigned int i = 0; i < 6; i++)
daniel@transgaming.com5cdd0582013-01-11 04:07:35 +0000341 {
shannon.woods@transgaming.com858d32f2013-01-25 21:49:59 +0000342 for (unsigned int j = 0; j < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS; j++)
343 {
344 mRenderTarget[i][j] = NULL;
345 }
daniel@transgaming.com5cdd0582013-01-11 04:07:35 +0000346 }
347
daniel@transgaming.comb2151e52013-01-11 04:06:24 +0000348 DXGI_FORMAT format = gl_d3d11::ConvertTextureFormat(internalformat);
349 // if the size is not positive this should be treated as an incomplete texture
350 // we handle that here by skipping the d3d texture creation
351 if (size > 0)
352 {
353 // adjust size if needed for compressed textures
354 int height = size;
355 gl::MakeValidSize(false, gl::IsCompressed(internalformat), &size, &height, &mLodOffset);
356
357 ID3D11Device *device = mRenderer->getDevice();
358
359 D3D11_TEXTURE2D_DESC desc;
360 desc.Width = size;
361 desc.Height = size;
362 desc.MipLevels = levels + mLodOffset;
363 desc.ArraySize = 6;
364 desc.Format = format;
365 desc.SampleDesc.Count = 1;
366 desc.SampleDesc.Quality = 0;
367 desc.Usage = D3D11_USAGE_DEFAULT;
368 desc.BindFlags = getBindFlags();
369 desc.CPUAccessFlags = 0;
370 desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
371
372 HRESULT result = device->CreateTexture2D(&desc, NULL, &mTexture);
373
374 if (FAILED(result))
375 {
376 ASSERT(result == E_OUTOFMEMORY);
377 ERR("Creating image failed.");
378 error(GL_OUT_OF_MEMORY);
379 }
daniel@transgaming.comb1154552013-01-11 04:11:02 +0000380 else
381 {
382 mTexture->GetDesc(&desc);
383 mMipLevels = desc.MipLevels;
shannon.woods@transgaming.com858d32f2013-01-25 21:49:59 +0000384 mTextureFormat = desc.Format;
385 mTextureWidth = desc.Width;
386 mTextureHeight = desc.Height;
daniel@transgaming.comb1154552013-01-11 04:11:02 +0000387 }
daniel@transgaming.comb2151e52013-01-11 04:06:24 +0000388 }
daniel@transgaming.comb2151e52013-01-11 04:06:24 +0000389}
390
391TextureStorage11_Cube::~TextureStorage11_Cube()
392{
393 if (mTexture)
shannon.woods@transgaming.com4b472352013-01-25 21:14:56 +0000394 {
daniel@transgaming.comb2151e52013-01-11 04:06:24 +0000395 mTexture->Release();
shannon.woods@transgaming.com4b472352013-01-25 21:14:56 +0000396 mTexture = NULL;
397 }
daniel@transgaming.com1e1b5e92013-01-11 04:11:27 +0000398
399 if (mSRV)
shannon.woods@transgaming.com4b472352013-01-25 21:14:56 +0000400 {
daniel@transgaming.com1e1b5e92013-01-11 04:11:27 +0000401 mSRV->Release();
shannon.woods@transgaming.com4b472352013-01-25 21:14:56 +0000402 mSRV = NULL;
403 }
404
405 for (unsigned int i = 0; i < 6; i++)
406 {
shannon.woods@transgaming.com858d32f2013-01-25 21:49:59 +0000407 for (unsigned int j = 0; j < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS; j++)
shannon.woods@transgaming.com4b472352013-01-25 21:14:56 +0000408 {
shannon.woods@transgaming.com858d32f2013-01-25 21:49:59 +0000409 delete mRenderTarget[i][j];
410 mRenderTarget[i][j] = NULL;
shannon.woods@transgaming.com4b472352013-01-25 21:14:56 +0000411 }
412 }
daniel@transgaming.comb2151e52013-01-11 04:06:24 +0000413}
414
415TextureStorage11_Cube *TextureStorage11_Cube::makeTextureStorage11_Cube(TextureStorage *storage)
416{
417 ASSERT(dynamic_cast<TextureStorage11_Cube*>(storage) != NULL);
418 return static_cast<TextureStorage11_Cube*>(storage);
419}
420
shannon.woods@transgaming.com858d32f2013-01-25 21:49:59 +0000421RenderTarget *TextureStorage11_Cube::getRenderTarget(GLenum faceTarget, int level)
daniel@transgaming.comb2151e52013-01-11 04:06:24 +0000422{
shannon.woods@transgaming.com858d32f2013-01-25 21:49:59 +0000423 unsigned int faceIdx = gl::TextureCubeMap::faceIndex(faceTarget);
424 if (level >= 0 && level < static_cast<int>(mMipLevels))
shannon.woods@transgaming.com4b472352013-01-25 21:14:56 +0000425 {
shannon.woods@transgaming.com858d32f2013-01-25 21:49:59 +0000426 if (!mRenderTarget[faceIdx][level])
427 {
428 ID3D11Device *device = mRenderer->getDevice();
429 HRESULT result;
430
431 if (getBindFlags() & D3D11_BIND_RENDER_TARGET)
432 {
433 D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
434 rtvDesc.Format = mTextureFormat;
435 rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
436 rtvDesc.Texture2DArray.MipSlice = level;
437 rtvDesc.Texture2DArray.FirstArraySlice = faceIdx;
438 rtvDesc.Texture2DArray.ArraySize = 1;
439
440 ID3D11RenderTargetView *rtv;
441 result = device->CreateRenderTargetView(mTexture, &rtvDesc, &rtv);
442
443 if (result == E_OUTOFMEMORY)
444 {
445 return error(GL_OUT_OF_MEMORY, static_cast<RenderTarget*>(NULL));
446 }
447 ASSERT(SUCCEEDED(result));
448
shannon.woods@transgaming.com183408d2013-01-25 21:50:07 +0000449 D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
450 srvDesc.Format = mTextureFormat;
451 srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
452 srvDesc.Texture2DArray.MostDetailedMip = level;
453 srvDesc.Texture2DArray.MipLevels = 1;
454 srvDesc.Texture2DArray.FirstArraySlice = faceIdx;
455 srvDesc.Texture2DArray.ArraySize = 1;
456
457 ID3D11ShaderResourceView *srv;
458 result = device->CreateShaderResourceView(mTexture, &srvDesc, &srv);
459
460 if (result == E_OUTOFMEMORY)
461 {
462 rtv->Release();
463 return error(GL_OUT_OF_MEMORY, static_cast<RenderTarget*>(NULL));
464 }
465 ASSERT(SUCCEEDED(result));
466
467 mRenderTarget[faceIdx][level] = new RenderTarget11(mRenderer, rtv, srv,
shannon.woods@transgaming.com858d32f2013-01-25 21:49:59 +0000468 std::max(mTextureWidth >> level, 1U),
469 std::max(mTextureHeight >> level, 1U));
470 }
471 else if (getBindFlags() & D3D11_BIND_DEPTH_STENCIL)
472 {
473 // TODO
474 UNIMPLEMENTED();
475 }
476 else UNREACHABLE();
477 }
478
479 return mRenderTarget[faceIdx][level];
shannon.woods@transgaming.com4b472352013-01-25 21:14:56 +0000480 }
481 else
482 {
shannon.woods@transgaming.com858d32f2013-01-25 21:49:59 +0000483 return NULL;
shannon.woods@transgaming.com4b472352013-01-25 21:14:56 +0000484 }
daniel@transgaming.comb2151e52013-01-11 04:06:24 +0000485}
486
487ID3D11Texture2D *TextureStorage11_Cube::getBaseTexture() const
488{
489 return mTexture;
490}
491
shannon.woods@transgaming.com858d32f2013-01-25 21:49:59 +0000492ID3D11ShaderResourceView *TextureStorage11_Cube::getSRV()
daniel@transgaming.comb50d5302013-01-11 04:07:29 +0000493{
shannon.woods@transgaming.com858d32f2013-01-25 21:49:59 +0000494 if (!mSRV)
495 {
496 ID3D11Device *device = mRenderer->getDevice();
497
498 D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
499 srvDesc.Format = mTextureFormat;
500 srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
501 srvDesc.TextureCube.MipLevels = (mMipLevels == 0 ? -1 : mMipLevels);
502 srvDesc.TextureCube.MostDetailedMip = 0;
503
504 HRESULT result = device->CreateShaderResourceView(mTexture, &srvDesc, &mSRV);
505
506 if (result == E_OUTOFMEMORY)
507 {
508 return error(GL_OUT_OF_MEMORY, static_cast<ID3D11ShaderResourceView*>(NULL));
509 }
510 ASSERT(SUCCEEDED(result));
511 }
512
daniel@transgaming.comb50d5302013-01-11 04:07:29 +0000513 return mSRV;
514}
515
daniel@transgaming.comb2151e52013-01-11 04:06:24 +0000516void TextureStorage11_Cube::generateMipmap(int face, int level)
517{
518 // TODO
519 UNIMPLEMENTED();
520}
521
daniel@transgaming.comb2151e52013-01-11 04:06:24 +0000522}