Create ShaderResourceViews for TextureStorage objects
TRAC #22250
Author: Shannon Woods
Signed-off-by: Nicolas Capens
Signed-off-by: Daniel Koch
git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1660 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/libGLESv2/renderer/TextureStorage11.cpp b/src/libGLESv2/renderer/TextureStorage11.cpp
index a1fe90e..4afa3d1 100644
--- a/src/libGLESv2/renderer/TextureStorage11.cpp
+++ b/src/libGLESv2/renderer/TextureStorage11.cpp
@@ -151,10 +151,12 @@
{
ID3D11Texture2D *surfaceTexture = swapchain->getOffscreenTexture();
mTexture = surfaceTexture;
+ mSRV = NULL;
D3D11_TEXTURE2D_DESC desc;
surfaceTexture->GetDesc(&desc);
+ initializeSRV(desc.Format, desc.MipLevels);
initializeRenderTarget(desc.Format, desc.Width, desc.Height);
}
@@ -162,6 +164,7 @@
: TextureStorage11(renderer, GetTextureBindFlags(gl_d3d11::ConvertTextureFormat(internalformat), usage, forceRenderable))
{
mTexture = NULL;
+ mSRV = NULL;
DXGI_FORMAT format = gl_d3d11::ConvertTextureFormat(internalformat);
// if the width or height is not positive this should be treated as an incomplete texture
// we handle that here by skipping the d3d texture creation
@@ -195,6 +198,7 @@
}
}
+ initializeSRV(format, levels + mLodOffset);
initializeRenderTarget(format, width, height);
}
@@ -220,6 +224,11 @@
return mTexture;
}
+ID3D11ShaderResourceView *TextureStorage11_2D::getSRV() const
+{
+ return mSRV;
+}
+
void TextureStorage11_2D::generateMipmap(int level)
{
// TODO
@@ -261,10 +270,35 @@
}
}
+void TextureStorage11_2D::initializeSRV(DXGI_FORMAT format, int levels)
+{
+ ASSERT(mSRV == NULL);
+
+ if (mTexture)
+ {
+ D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
+ srvDesc.Format = format;
+ srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
+ srvDesc.Texture2D.MostDetailedMip = 0;
+ srvDesc.Texture2D.MipLevels = levels;
+
+ ID3D11Device *device = mRenderer->getDevice();
+ HRESULT result = device->CreateShaderResourceView(mTexture, &srvDesc, &mSRV);
+
+ if (result == E_OUTOFMEMORY)
+ {
+ return error(GL_OUT_OF_MEMORY);
+ }
+
+ ASSERT(SUCCEEDED(result));
+ }
+}
+
TextureStorage11_Cube::TextureStorage11_Cube(Renderer *renderer, int levels, GLenum internalformat, GLenum usage, bool forceRenderable, int size)
: TextureStorage11(renderer, GetTextureBindFlags(gl_d3d11::ConvertTextureFormat(internalformat), usage, forceRenderable))
{
mTexture = NULL;
+ mSRV = NULL;
DXGI_FORMAT format = gl_d3d11::ConvertTextureFormat(internalformat);
// if the size is not positive this should be treated as an incomplete texture
// we handle that here by skipping the d3d texture creation
@@ -299,6 +333,7 @@
}
}
+ initializeSRV(format, levels + mLodOffset);
initializeRenderTarget(format, size);
}
@@ -324,6 +359,11 @@
return mTexture;
}
+ID3D11ShaderResourceView *TextureStorage11_Cube::getSRV() const
+{
+ return mSRV;
+}
+
void TextureStorage11_Cube::generateMipmap(int face, int level)
{
// TODO
@@ -374,4 +414,28 @@
}
}
+void TextureStorage11_Cube::initializeSRV(DXGI_FORMAT format, int levels)
+{
+ ASSERT(mSRV == NULL);
+
+ if (mTexture)
+ {
+ D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
+ srvDesc.Format = format;
+ srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
+ srvDesc.TextureCube.MipLevels = levels;
+ srvDesc.TextureCube.MostDetailedMip = 0;
+
+ ID3D11Device *device = mRenderer->getDevice();
+ HRESULT result = device->CreateShaderResourceView(mTexture, &srvDesc, &mSRV);
+
+ if (result == E_OUTOFMEMORY)
+ {
+ return error(GL_OUT_OF_MEMORY);
+ }
+
+ ASSERT(SUCCEEDED(result));
+ }
+}
+
}
\ No newline at end of file