|
13 | 13 | #include "tracy/TracyOpenGL.hpp"
|
14 | 14 |
|
15 | 15 | #include <array>
|
| 16 | +#include <cmath> |
16 | 17 |
|
17 | 18 | using namespace RTE;
|
18 | 19 |
|
@@ -415,50 +416,39 @@ void SceneLayerImpl<TRACK_DRAWINGS, STATIC_TEXTURE>::RegisterDrawing(const Vecto
|
415 | 416 |
|
416 | 417 | template <bool TRACK_DRAWINGS, bool STATIC_TEXTURE>
|
417 | 418 | void SceneLayerImpl<TRACK_DRAWINGS, STATIC_TEXTURE>::UpdateTargetRegion(const Box& targetBox) {
|
| 419 | + if constexpr (TRACK_DRAWINGS) { |
| 420 | + m_MainTexture->m_Bitmap = m_MainBitmap; |
| 421 | + } |
418 | 422 | if constexpr (!STATIC_TEXTURE) {
|
419 | 423 | RTEAssert(bitmap_color_depth(m_MainBitmap) == 8, "Truecolor scenelayer used for non gpu drawing!");
|
420 | 424 | std::vector<Box> updateRegions{};
|
421 |
| - m_MainTexture->m_Bitmap = m_MainBitmap; |
422 |
| - |
423 |
| - if (m_ScaledDimensions.m_X < targetBox.m_Width && m_ScaledDimensions.m_Y < targetBox.m_Height) { |
424 |
| - // Bitmap will be in frame entirely, upload all. |
425 |
| - updateRegions.emplace_back( |
426 |
| - Vector(), |
427 |
| - m_MainBitmap->w, |
428 |
| - m_MainBitmap->h |
429 |
| - ); |
430 |
| - } else { |
431 |
| - // Upload wrapped region |
432 |
| - |
433 |
| - Box cornerWrapEither( |
434 |
| - m_Offset / m_ScaleFactor, |
435 |
| - std::min((m_ScaledDimensions.m_X - m_Offset.m_X) / m_ScaleFactor.m_X,targetBox.m_Width / m_ScaleFactor.m_X), |
436 |
| - std::min((m_ScaledDimensions.m_Y - m_Offset.m_Y) / m_ScaleFactor.m_Y, targetBox.m_Height / m_ScaleFactor.m_Y) |
437 |
| - ); |
438 |
| - updateRegions.push_back(cornerWrapEither); |
439 |
| - |
440 |
| - if (m_WrapX && cornerWrapEither.m_Width < targetBox.m_Width) { |
441 |
| - updateRegions.emplace_back( |
442 |
| - Vector(0, m_Offset.m_Y) / m_ScaleFactor, |
443 |
| - (targetBox.m_Width + m_Offset.m_X - m_ScaledDimensions.m_X) / m_ScaleFactor.m_X, |
444 |
| - std::min(m_ScaledDimensions.m_Y - m_Offset.m_Y, targetBox.m_Height) / m_ScaleFactor.m_Y |
445 |
| - ); |
446 |
| - } |
447 |
| - if (m_WrapY && cornerWrapEither.m_Height < targetBox.m_Width) { |
448 |
| - updateRegions.emplace_back( |
449 |
| - Vector(m_Offset.m_X, 0) / m_ScaleFactor, |
450 |
| - std::min(m_ScaledDimensions.m_X - m_Offset.m_X, targetBox.m_Width) / m_ScaleFactor.m_X, |
451 |
| - (targetBox.m_Height + m_Offset.m_Y - m_ScaledDimensions.m_Y) / m_ScaleFactor.m_Y |
452 |
| - ); |
| 425 | + float bitmapWidth = m_MainBitmap->w; |
| 426 | + float bitmapHeight = m_MainBitmap->h; |
| 427 | + int areaToCoverX = (m_Offset.GetFloorIntX() + targetBox.GetCorner().GetFloorIntX() + targetBox.GetWidth()) / m_ScaleFactor.m_X; |
| 428 | + int areaToCoverY = (m_Offset.GetFloorIntY() + targetBox.GetCorner().GetFloorIntY() + targetBox.GetHeight()) / m_ScaleFactor.m_Y; |
| 429 | + Box scaledTarget(targetBox.m_Corner / m_ScaleFactor, targetBox.m_Width / m_ScaleFactor.m_X, targetBox.m_Height / m_ScaleFactor.m_Y); |
| 430 | + Vector scaledOffset(m_Offset/m_ScaleFactor); |
| 431 | + Box bitmapDimensions(Vector(), bitmapWidth, bitmapHeight); |
| 432 | + |
| 433 | + for (int tiledOffsetX = 0; tiledOffsetX < areaToCoverX;) { |
| 434 | + float destX = scaledTarget.GetCorner().GetFloorIntX() + tiledOffsetX - scaledOffset.GetFloorIntX(); |
| 435 | + |
| 436 | + for (int tiledOffsetY = 0; tiledOffsetY < areaToCoverY;) { |
| 437 | + float destY = scaledTarget.GetCorner().GetFloorIntY() + tiledOffsetY - scaledOffset.GetFloorIntY(); |
| 438 | + Box update = bitmapDimensions.GetIntersection({-Vector(destX, destY), scaledTarget.m_Width, scaledTarget.m_Height}); |
| 439 | + update.m_Corner = update.m_Corner.GetFloored(); |
| 440 | + update.m_Width = std::ceilf(update.m_Width) + 1; |
| 441 | + update.m_Height = std::ceilf(update.m_Height) + 1; |
| 442 | + updateRegions.emplace_back(update); |
| 443 | + if (!m_WrapY) { |
| 444 | + break; |
| 445 | + } |
| 446 | + tiledOffsetY += bitmapHeight; |
453 | 447 | }
|
454 |
| - |
455 |
| - if (m_WrapX && m_WrapY && cornerWrapEither.m_Height < targetBox.m_Height && cornerWrapEither.m_Width < targetBox.m_Width) { |
456 |
| - updateRegions.emplace_back( |
457 |
| - Vector(), |
458 |
| - (targetBox.m_Width + m_Offset.m_X - m_ScaledDimensions.m_X) / m_ScaleFactor.m_X, |
459 |
| - (targetBox.m_Height + m_Offset.m_Y - m_ScaledDimensions.m_Y) / m_ScaleFactor.m_Y |
460 |
| - ); |
| 448 | + if (!m_WrapX) { |
| 449 | + break; |
461 | 450 | }
|
| 451 | + tiledOffsetX += bitmapWidth; |
462 | 452 | }
|
463 | 453 |
|
464 | 454 | for (auto& region: updateRegions) {
|
|
0 commit comments