[Scummvm-git-logs] scummvm branch-2-5 -> c929bda5929a84290c5997629e664e5205d153a7

aquadran noreply at scummvm.org
Mon Dec 20 20:46:53 UTC 2021


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:
c929bda592 TINYGL: Ported viewport fix


Commit: c929bda5929a84290c5997629e664e5205d153a7
    https://github.com/scummvm/scummvm/commit/c929bda5929a84290c5997629e664e5205d153a7
Author: Paweł Kołodziejski (aquadran at gmail.com)
Date: 2021-12-20T21:46:48+01:00

Commit Message:
TINYGL: Ported viewport fix

Changed paths:
    engines/myst3/gfx_tinygl.cpp
    engines/myst3/gfx_tinygl.h
    graphics/tinygl/vertex.cpp


diff --git a/engines/myst3/gfx_tinygl.cpp b/engines/myst3/gfx_tinygl.cpp
index 013e59e414..f156954ae4 100644
--- a/engines/myst3/gfx_tinygl.cpp
+++ b/engines/myst3/gfx_tinygl.cpp
@@ -78,30 +78,26 @@ void TinyGLRenderer::init() {
 }
 
 void TinyGLRenderer::clear() {
+	tglClearColor(0.f, 0.f, 0.f, 1.f); // Solid black
 	tglClear(TGL_COLOR_BUFFER_BIT | TGL_DEPTH_BUFFER_BIT);
 	tglColor3f(1.0f, 1.0f, 1.0f);
 }
 
 void TinyGLRenderer::selectTargetWindow(Window *window, bool is3D, bool scaled) {
-	// NOTE: tinyGL viewport implementation needs to be checked as it doesn't behave the same as openGL
-
 	if (!window) {
 		// No window found ...
 		if (scaled) {
 			// ... in scaled mode draw in the original game screen area
-			Common::Rect vp = viewport();
-			tglViewport(vp.left, vp.top, vp.width(), vp.height());
-			//tglViewport(vp.left, _system->getHeight() - vp.top - vp.height(), vp.width(), vp.height());
+			_viewport = viewport();
 		} else {
 			// ... otherwise, draw on the whole screen
-			tglViewport(0, 0, _system->getWidth(), _system->getHeight());
+			_viewport = Common::Rect(_system->getWidth(), _system->getHeight());
 		}
 	} else {
 		// Found a window, draw inside it
-		Common::Rect vp = window->getPosition();
-		tglViewport(vp.left, vp.top, vp.width(), vp.height());
-		//tglViewport(vp.left, _system->getHeight() - vp.top - vp.height(), vp.width(), vp.height());
+		_viewport = window->getPosition();
 	}
+	tglViewport(_viewport.left, _system->getHeight() - _viewport.top - _viewport.height(), _viewport.width(), _viewport.height());
 
 	if (is3D) {
 		tglMatrixMode(TGL_PROJECTION);
@@ -171,14 +167,11 @@ void TinyGLRenderer::drawTexturedRect2D(const Common::Rect &screenRect, const Co
 		transparency = 1.0;
 	}
 
-	// HACK: tglBlit is not affected by the viewport, so we offset the draw coordinates here
-	int viewPort[4];
-	tglGetIntegerv(TGL_VIEWPORT, viewPort);
-
 	tglEnable(TGL_TEXTURE_2D);
 	tglDepthMask(TGL_FALSE);
 
-	Graphics::BlitTransform transform(sLeft + viewPort[0], sTop + viewPort[1]);
+	// HACK: tglBlit is not affected by the viewport, so we offset the draw coordinates here
+	Graphics::BlitTransform transform(sLeft + _viewport.left, sTop + _viewport.top);
 	transform.sourceRectangle(textureRect.left, textureRect.top, sWidth, sHeight);
 	transform.tint(transparency);
 	tglBlit(((TinyGLTexture *)texture)->getBlitTexture(), transform);
diff --git a/engines/myst3/gfx_tinygl.h b/engines/myst3/gfx_tinygl.h
index f57a658c89..d2d52c27d7 100644
--- a/engines/myst3/gfx_tinygl.h
+++ b/engines/myst3/gfx_tinygl.h
@@ -62,6 +62,7 @@ private:
 	void drawFace(uint face, Texture *texture);
 
 	TinyGL::FrameBuffer *_fb;
+	Common::Rect _viewport;
 };
 
 } // End of namespace Myst3
diff --git a/graphics/tinygl/vertex.cpp b/graphics/tinygl/vertex.cpp
index c66cbdc8f5..2d3303b51f 100644
--- a/graphics/tinygl/vertex.cpp
+++ b/graphics/tinygl/vertex.cpp
@@ -74,11 +74,14 @@ void gl_eval_viewport(GLContext *c) {
 
 	v = &c->viewport;
 
+	// v->ymin needs to be upside down for transformation
+	int ymin = c->fb->ysize - v->ysize - v->ymin;
 	v->trans.X = (float)(((v->xsize - 0.5) / 2.0) + v->xmin);
-	v->trans.Y = (float)(((v->ysize - 0.5) / 2.0) + v->ymin);
+	v->trans.Y = (float)(((v->ysize - 0.5) / 2.0) + ymin);
 	v->trans.Z = (float)(((zsize - 0.5) / 2.0) + ((1 << ZB_POINT_Z_FRAC_BITS)) / 2);
 
 	v->scale.X = (float)((v->xsize - 0.5) / 2.0);
+	// v->ysize needs to be upside down for scaling
 	v->scale.Y = (float)(-(v->ysize - 0.5) / 2.0);
 	v->scale.Z = (float)(-((zsize - 0.5) / 2.0));
 }




More information about the Scummvm-git-logs mailing list