//----------------------------------------------------------------------------// void Direct3D11Texture::saveToMemory(void* buffer) { if (!d_texture) return; String exception_msg; D3D11_TEXTURE2D_DESC tex_desc; d_texture->GetDesc(&tex_desc); tex_desc.Usage = D3D11_USAGE_STAGING; tex_desc.BindFlags = 0; tex_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; ID3D11Texture2D* offscreen; if (SUCCEEDED(d_device.d_device->CreateTexture2D(&tex_desc, 0, &offscreen))) { d_device.d_context->CopyResource(offscreen, d_texture); D3D11_MAPPED_SUBRESOURCE mapped_tex; if (SUCCEEDED(d_device.d_context->Map(offscreen, 0, D3D11_MAP_READ, 0, &mapped_tex))) { blitFromSurface(static_cast<uint32*>(mapped_tex.pData), static_cast<uint32*>(buffer), Size(static_cast<float>(tex_desc.Width), static_cast<float>(tex_desc.Height)), mapped_tex.RowPitch); d_device.d_context->Unmap(offscreen, 0); } else exception_msg.assign("ID3D11Texture2D::Map failed."); offscreen->Release(); } else exception_msg.assign( "ID3D11Device::CreateTexture2D failed for 'offscreen'."); if (!exception_msg.empty()) CEGUI_THROW(RendererException(exception_msg)); }
//----------------------------------------------------------------------------// void Direct3D10Texture::blitFromMemory(const void* sourceData, const Rectf& area) { if (!d_texture) return; uint32* buff = new uint32[static_cast<size_t>(area.getWidth()) * static_cast<size_t>(area.getHeight())]; blitFromSurface(static_cast<const uint32*>(sourceData), buff, area.getSize(), static_cast<size_t>(area.getWidth()) * 4); D3D10_BOX dst_box = {static_cast<UINT>(area.left()), static_cast<UINT>(area.top()), 0, static_cast<UINT>(area.right()), static_cast<UINT>(area.bottom()), 1}; d_device.UpdateSubresource(d_texture, 0, &dst_box, buff, static_cast<UINT>(area.getWidth()) * 4, 0); delete[] buff; }