[Scummvm-git-logs] scummvm master -> e4f3e73024a5a57c0fc7a53c8a36f9ff959ff22a
aquadran
noreply at scummvm.org
Wed Oct 16 05:24:29 UTC 2024
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
e4f3e73024 WINTERMUTE: Sync renderer setProjection function with original code
Commit: e4f3e73024a5a57c0fc7a53c8a36f9ff959ff22a
https://github.com/scummvm/scummvm/commit/e4f3e73024a5a57c0fc7a53c8a36f9ff959ff22a
Author: PaweÅ KoÅodziejski (aquadran at gmail.com)
Date: 2024-10-16T07:24:24+02:00
Commit Message:
WINTERMUTE: Sync renderer setProjection function with original code
Changed paths:
engines/wintermute/base/gfx/opengl/base_render_opengl3d.cpp
engines/wintermute/base/gfx/opengl/base_render_opengl3d_shader.cpp
engines/wintermute/base/gfx/xmath.cpp
diff --git a/engines/wintermute/base/gfx/opengl/base_render_opengl3d.cpp b/engines/wintermute/base/gfx/opengl/base_render_opengl3d.cpp
index 04c3cd8f14c..66177cdabb8 100644
--- a/engines/wintermute/base/gfx/opengl/base_render_opengl3d.cpp
+++ b/engines/wintermute/base/gfx/opengl/base_render_opengl3d.cpp
@@ -334,25 +334,48 @@ bool BaseRenderOpenGL3D::drawLine(int x1, int y1, int x2, int y2, uint32 color)
}
bool BaseRenderOpenGL3D::setProjection() {
- // is the viewport already set here?
- float viewportWidth = _viewportRect.right - _viewportRect.left;
- float viewportHeight = _viewportRect.bottom - _viewportRect.top;
+ DXMatrix matProj;
- float verticalViewAngle = _fov;
- float aspectRatio = viewportWidth / viewportHeight;
- float top = _nearClipPlane * tanf(verticalViewAngle * 0.5f);
+ float resWidth, resHeight;
+ float layerWidth, layerHeight;
+ float modWidth, modHeight;
+ bool customViewport;
+ getProjectionParams(&resWidth, &resHeight, &layerWidth, &layerHeight, &modWidth, &modHeight, &customViewport);
- float scaleMod = _height / viewportHeight;
+ Rect32 rc;
+ _gameRef->getCurrentViewportRect(&rc);
+ float viewportWidth = (float)rc.right - (float)rc.left;
+ float viewportHeight = (float)rc.bottom - (float)rc.top;
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(-top * aspectRatio, top * aspectRatio, -top, top, _nearClipPlane, _farClipPlane);
- glGetFloatv(GL_PROJECTION_MATRIX, _projectionMatrix.getData());
+ // margins
+ int mleft = rc.left;
+ int mright = resWidth - viewportWidth - rc.left;
+ int mtop = rc.top;
+ int mbottom = resHeight - viewportHeight - rc.top;
+
+ DXMatrixPerspectiveFovRH(&matProj, _fov, viewportWidth / viewportHeight, _nearClipPlane, _farClipPlane);
+
+ float scaleMod = resHeight / viewportHeight;
+ float scaleRatio = MAX(layerWidth / resWidth, layerHeight / resHeight) /** 1.05*/;
- _projectionMatrix(0, 0) *= scaleMod;
- _projectionMatrix(1, 1) *= scaleMod;
+ float offsetX = (float)_gameRef->_offsetX;
+ float offsetY = (float)_gameRef->_offsetY;
- glLoadMatrixf(_projectionMatrix.getData());
+ if (!customViewport) {
+ offsetX -= _drawOffsetX;
+ offsetY -= _drawOffsetY;
+ }
+
+ matProj.matrix._11 *= scaleRatio * scaleMod;
+ matProj.matrix._22 *= scaleRatio * scaleMod;
+ matProj.matrix._31 = -(offsetX + (mleft - mright) / 2 - modWidth) / viewportWidth * 2.0f;
+ matProj.matrix._32 = (offsetY + (mtop - mbottom) / 2 - modHeight) / viewportHeight * 2.0f;
+
+ Math::Matrix4 m;
+ m.setData(matProj);
+ _projectionMatrix = m;
+ glMatrixMode(GL_PROJECTION);
+ glLoadMatrixf(m.getData());
glMatrixMode(GL_MODELVIEW);
return true;
diff --git a/engines/wintermute/base/gfx/opengl/base_render_opengl3d_shader.cpp b/engines/wintermute/base/gfx/opengl/base_render_opengl3d_shader.cpp
index 6d2af1ce3d1..af6b85b3e0b 100644
--- a/engines/wintermute/base/gfx/opengl/base_render_opengl3d_shader.cpp
+++ b/engines/wintermute/base/gfx/opengl/base_render_opengl3d_shader.cpp
@@ -431,21 +431,46 @@ bool BaseRenderOpenGL3DShader::drawLine(int x1, int y1, int x2, int y2, uint32 c
}
bool BaseRenderOpenGL3DShader::setProjection() {
- // is the viewport already set here?
- float viewportWidth = _viewportRect.right - _viewportRect.left;
- float viewportHeight = _viewportRect.bottom - _viewportRect.top;
+ DXMatrix matProj;
- float verticalViewAngle = _fov;
- float aspectRatio = viewportWidth / viewportHeight;
+ float resWidth, resHeight;
+ float layerWidth, layerHeight;
+ float modWidth, modHeight;
+ bool customViewport;
+ getProjectionParams(&resWidth, &resHeight, &layerWidth, &layerHeight, &modWidth, &modHeight, &customViewport);
- float scaleMod = _height / viewportHeight;
+ Rect32 rc;
+ _gameRef->getCurrentViewportRect(&rc);
+ float viewportWidth = (float)rc.right - (float)rc.left;
+ float viewportHeight = (float)rc.bottom - (float)rc.top;
- float top = _nearClipPlane * tanf(verticalViewAngle * 0.5f);
+ // margins
+ int mleft = rc.left;
+ int mright = resWidth - viewportWidth - rc.left;
+ int mtop = rc.top;
+ int mbottom = resHeight - viewportHeight - rc.top;
- _projectionMatrix = Math::makeFrustumMatrix(-top * aspectRatio, top * aspectRatio, -top, top, _nearClipPlane, _farClipPlane);
+ DXMatrixPerspectiveFovRH(&matProj, _fov, viewportWidth / viewportHeight, _nearClipPlane, _farClipPlane);
- _projectionMatrix(0, 0) *= scaleMod;
- _projectionMatrix(1, 1) *= scaleMod;
+ float scaleMod = resHeight / viewportHeight;
+ float scaleRatio = MAX(layerWidth / resWidth, layerHeight / resHeight) /** 1.05*/;
+
+ float offsetX = (float)_gameRef->_offsetX;
+ float offsetY = (float)_gameRef->_offsetY;
+
+ if (!customViewport) {
+ offsetX -= _drawOffsetX;
+ offsetY -= _drawOffsetY;
+ }
+
+ matProj.matrix._11 *= scaleRatio * scaleMod;
+ matProj.matrix._22 *= scaleRatio * scaleMod;
+ matProj.matrix._31 = -(offsetX + (mleft - mright) / 2 - modWidth) / viewportWidth * 2.0f;
+ matProj.matrix._32 = (offsetY + (mtop - mbottom) / 2 - modHeight) / viewportHeight * 2.0f;
+
+ Math::Matrix4 m;
+ m.setData(matProj);
+ _projectionMatrix = m;
return true;
}
diff --git a/engines/wintermute/base/gfx/xmath.cpp b/engines/wintermute/base/gfx/xmath.cpp
index b9431fd98c1..b046dd87dbb 100644
--- a/engines/wintermute/base/gfx/xmath.cpp
+++ b/engines/wintermute/base/gfx/xmath.cpp
@@ -240,8 +240,8 @@ DXQuaternion *DXQuaternionRotationMatrix(DXQuaternion *out, const DXMatrix *m) {
DXMatrix *DXMatrixPerspectiveFovLH(DXMatrix *pout,float fovy, float aspect, float zn, float zf) {
DXMatrixIdentity(pout);
- pout->_m[0][0] = 1.0f / (aspect * tanf(fovy/2.0f));
- pout->_m[1][1] = 1.0f / tanf(fovy/2.0f);
+ pout->_m[0][0] = 1.0f / (aspect * tanf(fovy / 2.0f));
+ pout->_m[1][1] = 1.0f / tanf(fovy / 2.0f);
pout->_m[2][2] = zf / (zf - zn);
pout->_m[2][3] = 1.0f;
pout->_m[3][2] = (zf * zn) / (zn - zf);
More information about the Scummvm-git-logs
mailing list