Fix canvas textures getting clipped by wrong scissor box

This commit is contained in:
Magnus Norddahl 2022-10-28 22:24:21 +02:00 committed by Rachael Alexanderson
parent 1a1adc5c29
commit 181eda0a83
3 changed files with 10 additions and 2 deletions

View file

@ -170,6 +170,8 @@ void DFrameBuffer::SetViewportRects(IntRect *bounds)
mSceneViewport = *bounds;
mScreenViewport = *bounds;
mOutputLetterbox = *bounds;
mGameScreenWidth = mScreenViewport.width;
mGameScreenHeight = mScreenViewport.height;
return;
}
@ -216,6 +218,9 @@ void DFrameBuffer::SetViewportRects(IntRect *bounds)
mSceneViewport.width = (int)round(mSceneViewport.width * scaleX);
mSceneViewport.height = (int)round(mSceneViewport.height * scaleY);
}
mGameScreenWidth = GetWidth();
mGameScreenHeight = GetHeight();
}
//===========================================================================
@ -226,12 +231,12 @@ void DFrameBuffer::SetViewportRects(IntRect *bounds)
int DFrameBuffer::ScreenToWindowX(int x)
{
return mScreenViewport.left + (int)round(x * mScreenViewport.width / (float)GetWidth());
return mScreenViewport.left + (int)round(x * mScreenViewport.width / (float)mGameScreenWidth);
}
int DFrameBuffer::ScreenToWindowY(int y)
{
return mScreenViewport.top + mScreenViewport.height - (int)round(y * mScreenViewport.height / (float)GetHeight());
return mScreenViewport.top + mScreenViewport.height - (int)round(y * mScreenViewport.height / (float)mGameScreenHeight);
}
void DFrameBuffer::ScaleCoordsFromWindow(int16_t &x, int16_t &y)

View file

@ -147,6 +147,8 @@ public:
BoneBuffer* mBones = nullptr; // Model bones
IShadowMap mShadowMap;
int mGameScreenWidth = 0;
int mGameScreenHeight = 0;
IntRect mScreenViewport;
IntRect mSceneViewport;
IntRect mOutputLetterbox;

View file

@ -360,6 +360,7 @@ sector_t* RenderView(player_t* player)
{
screen->RenderTextureView(canvas->Tex, [=](IntRect& bounds)
{
screen->SetViewportRects(&bounds);
Draw2D(&canvas->Drawer, *screen->RenderState(), 0, 0, canvas->Tex->GetWidth(), canvas->Tex->GetHeight());
canvas->Drawer.Clear();
});