- textureRect.x = ( static_cast<float>( packPositionX ) +0.5f ) / mWidth; // left
- textureRect.y = ( static_cast<float>( packPositionY ) +0.5f ) / mHeight; // right
- textureRect.z = ( static_cast<float>( packPositionX + pixelData.GetWidth() )-0.5f ) / mWidth; // right
- textureRect.w = ( static_cast<float>( packPositionY + pixelData.GetHeight() )-0.5f ) / mHeight;// bottom
+ textureRect.x = (static_cast<float>(packPositionX) + 0.5f) / mWidth; // left
+ textureRect.y = (static_cast<float>(packPositionY) + 0.5f) / mHeight; // top
+ textureRect.z = (static_cast<float>(packPositionX + size.GetX()) - 0.5f) / mWidth; // right
+ textureRect.w = (static_cast<float>(packPositionY + size.GetY()) - 0.5f) / mHeight; // bottom
+
+ if(atlasUploadObserver)
+ {
+ // register to the observer,
+ // Not that a matching unregister call should be invoked in UploadToAtlas if the observer is still alive by then.
+ atlasUploadObserver->Register(*this);
+ }
+
+ return true;
+ }
+
+ return false;
+}
+
+bool ImageAtlas::Upload(Vector4& textureRect, PixelData pixelData)
+{
+ uint32_t packPositionX = 0;
+ uint32_t packPositionY = 0;
+ if(mPacker.Pack(pixelData.GetWidth(), pixelData.GetHeight(), packPositionX, packPositionY))
+ {
+ mAtlas.Upload(pixelData, 0u, 0u, packPositionX, packPositionY, pixelData.GetWidth(), pixelData.GetHeight());
+
+ // apply the half pixel correction
+ textureRect.x = (static_cast<float>(packPositionX) + 0.5f) / mWidth; // left
+ textureRect.y = (static_cast<float>(packPositionY) + 0.5f) / mHeight; // top
+ textureRect.z = (static_cast<float>(packPositionX + pixelData.GetWidth()) - 0.5f) / mWidth; // right
+ textureRect.w = (static_cast<float>(packPositionY + pixelData.GetHeight()) - 0.5f) / mHeight; // bottom