我想調整D3D11Texture2D的大小來縮小它。例如,我有一個1920x1080的紋理,我想以1280x720爲例進行縮放。 就這樣,你知道我沒有繪圖,我只想得到縮放的字節緩衝區。這裏是我的代碼:調整大小D3D11Texture2D DirectX 11
if (mRealTexture == nullptr) {
D3D11_TEXTURE2D_DESC description;
texture2D->GetDesc(&description);
description.BindFlags = 0;
description.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
description.Usage = D3D11_USAGE_STAGING;
description.MiscFlags = 0;
hr = mDevice->CreateTexture2D(&description, NULL, &mRealTexture);
if (FAILED(hr)) {
if (mRealTexture) {
mRealTexture->Release();
mRealTexture = nullptr;
}
return NULL;
}
}
mImmediateContext->CopyResource(mRealTexture, texture2D);
if (mScaledTexture == nullptr) {
D3D11_TEXTURE2D_DESC description;
texture2D->GetDesc(&description);
description.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
description.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
description.Width = 1440;
description.Height = 585;
description.MipLevels = 4;
description.ArraySize = 1;
description.SampleDesc.Count = 1;
description.SampleDesc.Quality = 0;
description.Usage = D3D11_USAGE_DEFAULT;
hr = mDevice->CreateTexture2D(&description, NULL, &mScaledTexture);
if (FAILED(hr)) {
if (mScaledTexture) {
mScaledTexture->Release();
mScaledTexture = nullptr;
}
return NULL;
}
} //I want to copy the mRealTexture on the mScaledTexture, map the scaledTexture and get the buffer.
感謝您的幫助
https://stackoverflow.com/a/24070486/8111865可能會幫助您 - 它不是工作代碼,而是關於如何使用Direct2D和DXGI調整資源大小的一般概述。 – ozeanix
太糟糕了沒有示例代碼...我認爲很多人需要這樣做... 對於我來說,理解要採取的步驟太含糊。 (我的意思是代碼) – DevAndroid
我知道這聽起來很古怪,我並不是這個意思,但是試着爲概述編寫逼真的僞代碼,併爲每個接口使用MSDN文檔,以便慢慢將它變成真正的實現。首先處理小部件並觀察您的HRESULT。我發現使用DirectX和DirectShow和Media Foundation等類似結構化的東西可能會非常令人沮喪,但它只是花費時間和精力去投資才能真正學習它。一旦你這樣做了,像這樣的問題的解決方案將會非常自然,因爲你對DirectX可以做什麼以及如何去做有着豐富的知識。 – ozeanix