- Fix mouse position being wrong when vid_scalemode is active

This commit is contained in:
Magnus Norddahl 2017-07-29 19:26:53 +02:00
parent 3540440bf6
commit 7d21fe6d75
4 changed files with 59 additions and 17 deletions

View file

@ -548,3 +548,18 @@ void OpenGLFrameBuffer::GameRestart()
gl_GenerateGlobalBrightmapFromColormap(); gl_GenerateGlobalBrightmapFromColormap();
} }
void OpenGLFrameBuffer::ScaleCoordsFromWindow(int16_t &x, int16_t &y)
{
int letterboxX = GLRenderer->mOutputLetterbox.left;
int letterboxY = GLRenderer->mOutputLetterbox.top;
int letterboxWidth = GLRenderer->mOutputLetterbox.width;
int letterboxHeight = GLRenderer->mOutputLetterbox.height;
// Subtract the LB video mode letterboxing
if (IsFullscreen())
y -= (GetTrueHeight() - VideoHeight) / 2;
x = int16_t((x - letterboxX) * Width / letterboxWidth);
y = int16_t((y - letterboxY) * Height / letterboxHeight);
}

View file

@ -82,6 +82,8 @@ public:
void SetVSync(bool vsync); void SetVSync(bool vsync);
void ScaleCoordsFromWindow(int16_t &x, int16_t &y) override;
bool HWGammaActive = false; // Are we using hardware or software gamma? bool HWGammaActive = false; // Are we using hardware or software gamma?
std::shared_ptr<FGLDebug> mDebug; // Debug API std::shared_ptr<FGLDebug> mDebug; // Debug API
private: private:

View file

@ -714,14 +714,10 @@ void OpenGLSWFrameBuffer::DrawTriangleList(int minIndex, int numVertices, int st
glDrawRangeElements(GL_TRIANGLES, minIndex, minIndex + numVertices - 1, primitiveCount * 3, GL_UNSIGNED_SHORT, (const void*)(startIndex * sizeof(uint16_t))); glDrawRangeElements(GL_TRIANGLES, minIndex, minIndex + numVertices - 1, primitiveCount * 3, GL_UNSIGNED_SHORT, (const void*)(startIndex * sizeof(uint16_t)));
} }
void OpenGLSWFrameBuffer::Present() void OpenGLSWFrameBuffer::GetLetterboxFrame(int &letterboxX, int &letterboxY, int &letterboxWidth, int &letterboxHeight)
{ {
int clientWidth = GetClientWidth(); int clientWidth = GetClientWidth();
int clientHeight = GetClientHeight(); int clientHeight = GetClientHeight();
if (clientWidth > 0 && clientHeight > 0)
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, clientWidth, clientHeight);
float scaleX, scaleY; float scaleX, scaleY;
if (ViewportIsScaled43()) if (ViewportIsScaled43())
@ -735,11 +731,23 @@ void OpenGLSWFrameBuffer::Present()
scaleY = scaleX; scaleY = scaleX;
} }
int letterboxWidth = (int)round(Width * scaleX); letterboxWidth = (int)round(Width * scaleX);
int letterboxHeight = (int)round(Height * scaleY); letterboxHeight = (int)round(Height * scaleY);
int letterboxX = (clientWidth - letterboxWidth) / 2; letterboxX = (clientWidth - letterboxWidth) / 2;
int letterboxY = (clientHeight - letterboxHeight) / 2; letterboxY = (clientHeight - letterboxHeight) / 2;
}
void OpenGLSWFrameBuffer::Present()
{
int clientWidth = GetClientWidth();
int clientHeight = GetClientHeight();
if (clientWidth > 0 && clientHeight > 0)
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, clientWidth, clientHeight);
int letterboxX, letterboxY, letterboxWidth, letterboxHeight;
GetLetterboxFrame(letterboxX, letterboxY, letterboxWidth, letterboxHeight);
DrawLetterbox(letterboxX, letterboxY, letterboxWidth, letterboxHeight); DrawLetterbox(letterboxX, letterboxY, letterboxWidth, letterboxHeight);
glViewport(letterboxX, letterboxY, letterboxWidth, letterboxHeight); glViewport(letterboxX, letterboxY, letterboxWidth, letterboxHeight);
@ -3830,3 +3838,16 @@ void OpenGLSWFrameBuffer::SetPaletteTexture(HWTexture *texture, int count, uint3
SetConstant(PSCONST_PaletteMod, 255 * fcount, 0.5f * fcount, 0, 0); SetConstant(PSCONST_PaletteMod, 255 * fcount, 0.5f * fcount, 0, 0);
SetTexture(1, texture); SetTexture(1, texture);
} }
void OpenGLSWFrameBuffer::ScaleCoordsFromWindow(int16_t &x, int16_t &y)
{
int letterboxX, letterboxY, letterboxWidth, letterboxHeight;
GetLetterboxFrame(letterboxX, letterboxY, letterboxWidth, letterboxHeight);
// Subtract the LB video mode letterboxing
if (IsFullscreen())
y -= (GetTrueHeight() - VideoHeight) / 2;
x = int16_t((x - letterboxX) * Width / letterboxWidth);
y = int16_t((y - letterboxY) * Height / letterboxHeight);
}

View file

@ -72,6 +72,8 @@ public:
int GetTrueHeight() override { return TrueHeight; } int GetTrueHeight() override { return TrueHeight; }
#endif #endif
void ScaleCoordsFromWindow(int16_t &x, int16_t &y) override;
private: private:
struct FBVERTEX struct FBVERTEX
{ {
@ -195,6 +197,8 @@ private:
void DrawTriangleList(int minIndex, int numVertices, int startIndex, int primitiveCount); void DrawTriangleList(int minIndex, int numVertices, int startIndex, int primitiveCount);
void Present(); void Present();
void GetLetterboxFrame(int &x, int &y, int &width, int &height);
static void BgraToRgba(uint32_t *dest, const uint32_t *src, int width, int height, int srcpitch); static void BgraToRgba(uint32_t *dest, const uint32_t *src, int width, int height, int srcpitch);
void BindFBBuffer(); void BindFBBuffer();