| 147 | } |
| 148 | |
| 149 | DX11GraphicsObject* DX11Engine::Share(std::shared_ptr<Texture2> const& texture, DX11Engine* engine) |
| 150 | { |
| 151 | LogAssert(texture != nullptr && engine != nullptr, "Invalid input."); |
| 152 | LogAssert(texture->IsShared(), "The texture must allow sharing."); |
| 153 | |
| 154 | DX11GraphicsObject* dxTexture = static_cast<DX11GraphicsObject*>(Get(texture)); |
| 155 | if (dxTexture) |
| 156 | { |
| 157 | // The texture is already shared by 'this', so nothing to do. |
| 158 | return dxTexture; |
| 159 | } |
| 160 | |
| 161 | dxTexture = static_cast<DX11GraphicsObject*>(engine->Get(texture)); |
| 162 | if (dxTexture) |
| 163 | { |
| 164 | std::shared_ptr<DX11GraphicsObject> dxShared; |
| 165 | if (texture->GetType() == GT_TEXTURE2) |
| 166 | { |
| 167 | dxShared = std::make_shared<DX11Texture2>(mDevice, static_cast<DX11Texture2 const*>(dxTexture)); |
| 168 | } |
| 169 | else if (texture->GetType() == GT_TEXTURE_RT) |
| 170 | { |
| 171 | dxShared = std::make_shared<DX11TextureRT>(mDevice, static_cast<DX11TextureRT const*>(dxTexture)); |
| 172 | } |
| 173 | else // texture->GetType() == GT_TEXTURE_DS |
| 174 | { |
| 175 | dxShared = std::make_shared<DX11TextureDS>(mDevice, static_cast<DX11TextureDS const*>(dxTexture)); |
| 176 | } |
| 177 | mGOMapMutex.lock(); |
| 178 | mGOMap.insert(std::make_pair(texture.get(), dxShared)); |
| 179 | mGOMapMutex.unlock(); |
| 180 | return dxShared.get(); |
| 181 | } |
| 182 | |
| 183 | // The texture is not bound to 'engine'; create a new binding for 'this'. |
| 184 | return static_cast<DX11GraphicsObject*>(Bind(texture)); |
| 185 | } |
| 186 | |
| 187 | D3D11_MAPPED_SUBRESOURCE DX11Engine::MapForWrite(std::shared_ptr<Resource> const& resource, uint32_t sri) |
| 188 | { |