|
@@ -90,7 +90,8 @@ DX11Textur::DX11Textur(ID3D11Device* device, ID3D11DeviceContext* context)
|
|
|
view(0),
|
|
|
device(device),
|
|
|
context(context),
|
|
|
- renderTarget(0)
|
|
|
+ renderTarget(0),
|
|
|
+ useMips(1)
|
|
|
{}
|
|
|
|
|
|
DX11Textur::~DX11Textur()
|
|
@@ -117,27 +118,44 @@ bool DX11Textur::updateTextur()
|
|
|
bufferDesc.Width = bild->getBreite();
|
|
|
bufferDesc.Height = bild->getHeight();
|
|
|
bufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
|
|
|
- bufferDesc.BindFlags = (renderTarget ? D3D11_BIND_RENDER_TARGET : 0)
|
|
|
+ bufferDesc.BindFlags
|
|
|
+ = (renderTarget || useMips ? D3D11_BIND_RENDER_TARGET : 0)
|
|
|
| D3D11_BIND_SHADER_RESOURCE;
|
|
|
- bufferDesc.CPUAccessFlags = renderTarget ? 0 : D3D11_CPU_ACCESS_WRITE;
|
|
|
+ bufferDesc.CPUAccessFlags = renderTarget || useMips ? 0 : D3D11_CPU_ACCESS_WRITE;
|
|
|
bufferDesc.SampleDesc.Count = 1;
|
|
|
- bufferDesc.MipLevels = 1;
|
|
|
- bufferDesc.Usage
|
|
|
- = renderTarget ? D3D11_USAGE_DEFAULT : D3D11_USAGE_DYNAMIC;
|
|
|
+ bufferDesc.MipLevels = useMips ? 0 : 1;
|
|
|
+ bufferDesc.Usage = renderTarget || useMips ? D3D11_USAGE_DEFAULT
|
|
|
+ : D3D11_USAGE_DYNAMIC;
|
|
|
+ bufferDesc.MiscFlags = useMips ? D3D11_RESOURCE_MISC_GENERATE_MIPS : 0;
|
|
|
HRESULT r = device->CreateTexture2D(&bufferDesc, 0, &txt);
|
|
|
if (r != S_OK) return 0;
|
|
|
}
|
|
|
if (!renderTarget && (bild->getRend() || changed))
|
|
|
{
|
|
|
changed = 0;
|
|
|
- D3D11_MAPPED_SUBRESOURCE buffer;
|
|
|
- context->Map(txt, 0, D3D11_MAP::D3D11_MAP_WRITE_DISCARD, 0, &buffer);
|
|
|
- int* bgBuff = bild->getBuffer();
|
|
|
- int tmpBr = 4 * bild->getBreite();
|
|
|
- for (int y = 0, pitch = 0, bry = 0; y < bild->getHeight();
|
|
|
- ++y, pitch += buffer.RowPitch, bry += bild->getBreite())
|
|
|
- memcpy(&((BYTE*)buffer.pData)[pitch], (void*)&(bgBuff[bry]), tmpBr);
|
|
|
- context->Unmap(txt, 0);
|
|
|
+ if (useMips)
|
|
|
+ {
|
|
|
+ context->UpdateSubresource(txt,
|
|
|
+ 0,
|
|
|
+ 0,
|
|
|
+ bild->getBuffer(),
|
|
|
+ 4 * bild->getBreite(),
|
|
|
+ 4 * bild->getBreite() * bild->getHeight());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ D3D11_MAPPED_SUBRESOURCE buffer;
|
|
|
+ context->Map(
|
|
|
+ txt, 0, D3D11_MAP::D3D11_MAP_WRITE_DISCARD, 0, &buffer);
|
|
|
+ int* bgBuff = bild->getBuffer();
|
|
|
+ int tmpBr = 4 * bild->getBreite();
|
|
|
+ for (int y = 0, pitch = 0, bry = 0; y < bild->getHeight();
|
|
|
+ ++y, pitch += buffer.RowPitch, bry += bild->getBreite())
|
|
|
+ memcpy(&((BYTE*)buffer.pData)[pitch],
|
|
|
+ (void*)&(bgBuff[bry]),
|
|
|
+ tmpBr);
|
|
|
+ context->Unmap(txt, 0);
|
|
|
+ }
|
|
|
}
|
|
|
if (!view || lastGr != bild->getSize())
|
|
|
{
|
|
@@ -147,9 +165,10 @@ bool DX11Textur::updateTextur()
|
|
|
memset(&resourceDesk, 0, sizeof(D3D11_SHADER_RESOURCE_VIEW_DESC));
|
|
|
resourceDesk.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
|
|
|
resourceDesk.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
|
|
|
- resourceDesk.Texture2D.MipLevels = 1;
|
|
|
+ resourceDesk.Texture2D.MipLevels = useMips ? -1 : 1;
|
|
|
HRESULT r = device->CreateShaderResourceView(txt, &resourceDesk, &view);
|
|
|
if (r != S_OK) return 0;
|
|
|
+ if (context && useMips) context->GenerateMips(view);
|
|
|
}
|
|
|
lastGr = bild->getSize();
|
|
|
#endif
|
|
@@ -177,9 +196,16 @@ DX11Textur::operator ID3D11Texture2D*() const
|
|
|
//! specifies that this texture is used as a render target
|
|
|
void DX11Textur::setRenderTarget(bool rt)
|
|
|
{
|
|
|
+ if (rt) useMips = 0;
|
|
|
renderTarget = rt;
|
|
|
}
|
|
|
|
|
|
+//! specifies if a mip map should be generated
|
|
|
+void DX11Textur::setUseMips(bool useMips)
|
|
|
+{
|
|
|
+ this->useMips = useMips;
|
|
|
+}
|
|
|
+
|
|
|
//! copy the texture to an image
|
|
|
void DX11Textur::copyToImage(Bild* zB)
|
|
|
{
|