Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool TextureClass::Initialize(ID3D11Device* device, WCHAR* filename)
- {
- HRESULT result;
- // Load the texture in.
- TexMetadata md;
- ScratchImage si;
- result = LoadFromDDSFile(filename, 0, &md, si);
- if (FAILED(result))
- {
- return false;
- }
- result = CreateShaderResourceViewEx(device, si.GetImages(), si.GetImageCount(), _In_ md, D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET, 0, 0, false, &m_texture);
- ID3D11Resource * pResource = nullptr;
- m_texture->GetResource(&pResource);
- ID3D11Texture2D * pTexture = nullptr;
- result = pResource->QueryInterface(&pTexture);
- if (FAILED(result))
- {
- return false;
- }
- IDXGISurface *pDxgiSurface = NULL;
- result = pTexture->QueryInterface(&pDxgiSurface);
- if (FAILED(result))
- {
- return false;
- }
- ID2D1Factory1 * pD2DFactory = nullptr;
- result = D2D1CreateFactory(D2D1_FACTORY_TYPE::D2D1_FACTORY_TYPE_MULTI_THREADED, &pD2DFactory);
- if (FAILED(result))
- {
- return false;
- }
- D3D11_TEXTURE2D_DESC desc;
- pTexture->GetDesc(&desc);
- ID2D1RenderTarget * pRenderTarget = nullptr;
- // Create a D2D render target which can draw into our offscreen D3D
- // surface. Given that we use a constant size for the texture, we
- // fix the DPI at 96.
- D2D1_RENDER_TARGET_PROPERTIES props =
- D2D1::RenderTargetProperties(
- D2D1_RENDER_TARGET_TYPE_HARDWARE,
- D2D1::PixelFormat(DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_PREMULTIPLIED),
- 96,
- 96
- );
- result = pD2DFactory->CreateDxgiSurfaceRenderTarget(
- pDxgiSurface,
- &props,
- &pRenderTarget
- );
- if (FAILED(result))
- {
- return false;
- }
- ID2D1DeviceContext * pD2DContext = nullptr;
- result = pRenderTarget->QueryInterface(&pD2DContext);
- if (FAILED(result))
- {
- return false;
- }
- ID2D1Bitmap * pBitmap = nullptr;
- D2D1_BITMAP_PROPERTIES bitmapProps;
- bitmapProps.pixelFormat.format = desc.Format;
- bitmapProps.pixelFormat.alphaMode = D2D1_ALPHA_MODE_PREMULTIPLIED;
- bitmapProps.dpiX = 96;
- bitmapProps.dpiY = 96;
- result = pD2DContext->CreateSharedBitmap(__uuidof(IDXGISurface), pDxgiSurface, &bitmapProps, &pBitmap);
- if (FAILED(result))
- {
- return false;
- }
- /*ID2D1Effect * colorMatrixEffect = nullptr;
- result = pD2DContext->CreateEffect(CLSID_D2D1ColorMatrix, &colorMatrixEffect);
- if (FAILED(result))
- {
- return false;
- }
- colorMatrixEffect->SetInput(0, pBitmap);
- D2D1_MATRIX_5X4_F matrix = D2D1::Matrix5x4F(
- 0, 0, 1, 0,
- 0, 1, 0, 0,
- 1, 0, 1, 0,
- 0, 0, 0, 1,
- 0, 1, 0, 0
- );
- result = colorMatrixEffect->SetValue(D2D1_COLORMATRIX_PROP_COLOR_MATRIX, matrix);
- if (FAILED(result))
- {
- return false;
- }*/
- /*ID2D1Effect * gaussianBlurEffect;
- pD2DContext->CreateEffect(CLSID_D2D1GaussianBlur, &gaussianBlurEffect);
- gaussianBlurEffect->SetInput(0, pBitmap);
- gaussianBlurEffect->SetValue(D2D1_GAUSSIANBLUR_PROP_STANDARD_DEVIATION, 3.0f);*/
- ID2D1Effect * directionalBlurEffect;
- pD2DContext->CreateEffect(CLSID_D2D1DirectionalBlur, &directionalBlurEffect);
- directionalBlurEffect->SetInput(0, pBitmap);
- directionalBlurEffect->SetValue(D2D1_DIRECTIONALBLUR_PROP_STANDARD_DEVIATION, 7.0f);
- /*ID2D1Effect * convolveMatrixEffect;
- pD2DContext->CreateEffect(CLSID_D2D1ConvolveMatrix, &convolveMatrixEffect);
- convolveMatrixEffect->SetInput(0, pBitmap);
- float matrix[9] = { -1, 8, -1, 2, 23, 2, -1, 8, -1 };
- convolveMatrixEffect->SetValue(D2D1_CONVOLVEMATRIX_PROP_KERNEL_MATRIX, matrix);*/
- /*ID2D1Effect * saturationEffect;
- pD2DContext->CreateEffect(CLSID_D2D1Saturation, &saturationEffect);
- saturationEffect->SetInput(0, pBitmap);
- saturationEffect->SetValue(D2D1_SATURATION_PROP_SATURATION, 0.0f);*/
- pD2DContext->BeginDraw();
- pD2DContext->DrawImage(directionalBlurEffect);
- pD2DContext->EndDraw();
- if(FAILED(result))
- {
- return false;
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement