Crop both subresources to the given bitmaps as well as each others dimensions; and run some basic checks on them (IsValid, formats matching, ...). Returns true if all that passed and a copy would make sense.
| 224 | // and run some basic checks on them (IsValid, formats matching, ...). |
| 225 | // Returns true if all that passed and a copy would make sense. |
| 226 | bool Crop( Tr2TextureSubresource& sourceSR, |
| 227 | const Tr2BitmapDimensions& sourceBD, |
| 228 | Tr2TextureSubresource& destSR, |
| 229 | const Tr2BitmapDimensions& destBD ) |
| 230 | { |
| 231 | if( destSR.GetFaceCount() != sourceSR.GetFaceCount() ) |
| 232 | { |
| 233 | return false; |
| 234 | } |
| 235 | |
| 236 | if( sourceSR.HasBox() && destSR.HasBox() && ( destSR.GetDepth() != sourceSR.GetDepth() ) ) |
| 237 | { |
| 238 | return false; |
| 239 | } |
| 240 | |
| 241 | sourceSR.ClampToTexture( sourceBD ); |
| 242 | destSR.ClampToTexture( destBD ); |
| 243 | |
| 244 | if( sourceSR.GetWidth() < destSR.GetWidth() ) |
| 245 | { |
| 246 | destSR.m_box.right = destSR.m_box.left + sourceSR.GetWidth(); |
| 247 | } |
| 248 | else |
| 249 | { |
| 250 | sourceSR.m_box.right = sourceSR.m_box.left + destSR.GetWidth(); |
| 251 | } |
| 252 | |
| 253 | if( sourceSR.GetHeight() < destSR.GetHeight() ) |
| 254 | { |
| 255 | destSR.m_box.bottom = destSR.m_box.top + sourceSR.GetHeight(); |
| 256 | } |
| 257 | else |
| 258 | { |
| 259 | sourceSR.m_box.bottom = sourceSR.m_box.top + destSR.GetHeight(); |
| 260 | } |
| 261 | |
| 262 | sourceSR.ClampToTexture( sourceBD ); |
| 263 | destSR.ClampToTexture( destBD ); |
| 264 | |
| 265 | if( !sourceSR.IsValid() || !destSR.IsValid() ) |
| 266 | { |
| 267 | return false; |
| 268 | } |
| 269 | |
| 270 | return true; |
| 271 | } |
| 272 | |
| 273 | // Check if we're moving to a smaller mip, and if so, shrink the rectangle pointed at by |
| 274 | // sub in half. |