[Scummvm-git-logs] scummvm master -> a4e50f9f9c93a27679d2e7707a82e607c2540a59

aquadran noreply at scummvm.org
Wed Dec 15 19:31:11 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:
a4e50f9f9c GRIM: Synchronise portions of opengl vs tinygl


Commit: a4e50f9f9c93a27679d2e7707a82e607c2540a59
    https://github.com/scummvm/scummvm/commit/a4e50f9f9c93a27679d2e7707a82e607c2540a59
Author: Paweł Kołodziejski (aquadran at gmail.com)
Date: 2021-12-15T20:31:04+01:00

Commit Message:
GRIM: Synchronise portions of opengl vs tinygl

Changed paths:
    engines/grim/gfx_opengl.cpp
    engines/grim/gfx_tinygl.cpp


diff --git a/engines/grim/gfx_opengl.cpp b/engines/grim/gfx_opengl.cpp
index 7a902e85ca..03061e7c2d 100644
--- a/engines/grim/gfx_opengl.cpp
+++ b/engines/grim/gfx_opengl.cpp
@@ -149,6 +149,8 @@ void GfxOpenGL::setupScreen(int screenW, int screenH) {
 	GLfloat diffuseReflectance[] = { 1.0f, 1.0f, 1.0f, 1.0f };
 	glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuseReflectance);
 
+	glClearStencil(~0);
+
 	if (g_grim->getGameType() == GType_GRIM) {
 		glPolygonOffset(-6.0, -6.0);
 	}
@@ -244,7 +246,7 @@ void GfxOpenGL::positionCamera(const Math::Vector3d &pos, const Math::Vector3d &
 }
 
 void GfxOpenGL::positionCamera(const Math::Vector3d &pos, const Math::Matrix4 &rot) {
-	glScaled(1, 1, -1);
+	glScaled(1.0f, 1.0f, -1.0f);
 	_currentPos = pos;
 	_currentRot = rot;
 }
@@ -497,6 +499,8 @@ void GfxOpenGL::getActorScreenBBox(const Actor *actor, Common::Point &p1, Common
 	// Set up the camera coordinate system
 	glMatrixMode(GL_MODELVIEW);
 	glPushMatrix();
+
+	// Apply the view transform.
 	Math::Matrix4 worldRot = _currentRot;
 	glMultMatrixf(worldRot.getData());
 	glTranslatef(-_currentPos.x(), -_currentPos.y(), -_currentPos.z());
@@ -642,14 +646,9 @@ void GfxOpenGL::finishActorDraw() {
 		glDisable(GL_CULL_FACE);
 	}
 
-	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
 	_currentActor = nullptr;
 }
 
-void GfxOpenGL::setShadow(Shadow *shadow) {
-	_currentShadowArray = shadow;
-}
-
 void GfxOpenGL::drawShadowPlanes() {
 /*	glColor3f(1.0f, 1.0f, 1.0f);
 	_currentShadowArray->planeList.begin();
@@ -671,18 +670,17 @@ void GfxOpenGL::drawShadowPlanes() {
 		glTranslatef(-_currentPos.x(), -_currentPos.y(), -_currentPos.z());
 	}
 
-
 	glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
 	glDepthMask(GL_FALSE);
-	glClearStencil(~0);
-	glClear(GL_STENCIL_BUFFER_BIT);
 
+	glClear(GL_STENCIL_BUFFER_BIT);
 	glEnable(GL_STENCIL_TEST);
 	glStencilFunc(GL_ALWAYS, 1, (GLuint)~0);
 	glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
+
 	glDisable(GL_LIGHTING);
 	glDisable(GL_TEXTURE_2D);
-	glColor4f(1, 1, 1, 1);
+	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
 	for (SectorListType::iterator i = _currentShadowArray->planeList.begin(); i != _currentShadowArray->planeList.end(); ++i) {
 		Sector *shadowSector = i->sector;
 		glBegin(GL_POLYGON);
@@ -699,6 +697,10 @@ void GfxOpenGL::drawShadowPlanes() {
 	glPopMatrix();
 }
 
+void GfxOpenGL::setShadow(Shadow *shadow) {
+	_currentShadowArray = shadow;
+}
+
 void GfxOpenGL::setShadowMode() {
 	GfxBase::setShadowMode();
 }
@@ -853,7 +855,7 @@ void GfxOpenGL::drawSprite(const Sprite *sprite) {
 	if (g_grim->getGameType() == GType_GRIM) {
 		glEnable(GL_ALPHA_TEST);
 		glAlphaFunc(GL_GEQUAL, 0.5f);
-	}  else if (sprite->_flags2 & Sprite::AlphaTest) {
+	} else if (sprite->_flags2 & Sprite::AlphaTest) {
 		glEnable(GL_ALPHA_TEST);
 		glAlphaFunc(GL_GEQUAL, 0.1f);
 	} else {
@@ -885,8 +887,8 @@ void GfxOpenGL::drawSprite(const Sprite *sprite) {
 			glTexCoord2f(sprite->_texCoordX[i], sprite->_texCoordY[i]);
 			glVertex3f(vertexX[i] * halfWidth, vertexY[i] * halfHeight, 0.0f);
 		}
-		glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
 		glEnd();
+		glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
 	} else {
 		// In Grim, the bottom edge of the sprite is at y=0 and
 		// the texture is flipped along the X-axis.
@@ -1184,7 +1186,7 @@ void GfxOpenGL::drawBitmap(const Bitmap *bitmap, int dx, int dy, uint32 layer) {
 		glDisable(GL_DEPTH_TEST);
 		glDepthMask(GL_FALSE);
 
-	        glColor3f(1.0f, 1.0f, 1.0f);
+		glColor3f(1.0f, 1.0f, 1.0f);
 
 		BitmapData *data = bitmap->_data;
 		GLuint *textures = (GLuint *)bitmap->getTexIds();
diff --git a/engines/grim/gfx_tinygl.cpp b/engines/grim/gfx_tinygl.cpp
index fdf7985a9f..851b129d43 100644
--- a/engines/grim/gfx_tinygl.cpp
+++ b/engines/grim/gfx_tinygl.cpp
@@ -91,6 +91,7 @@ void GfxTinyGL::setupScreen(int screenW, int screenH) {
 	_storedDisplay->create(_gameWidth, _gameHeight, _pixelFormat);
 
 	_currentShadowArray = nullptr;
+	tglViewport(0, 0, _screenWidth, _screenHeight);
 
 	TGLfloat ambientSource[] = { 0.0f, 0.0f, 0.0f, 1.0f };
 	tglLightModelfv(TGL_LIGHT_MODEL_AMBIENT, ambientSource);
@@ -98,8 +99,10 @@ void GfxTinyGL::setupScreen(int screenW, int screenH) {
 	tglMaterialfv(TGL_FRONT, TGL_DIFFUSE, diffuseReflectance);
 	
 	tglClearStencil(0xff);
-	tglStencilFunc(TGL_ALWAYS, 1, 0xff);
-	tglStencilOp(TGL_REPLACE, TGL_REPLACE, TGL_REPLACE);
+
+	if (g_grim->getGameType() == GType_GRIM) {
+		tglPolygonOffset(-6.0, -6.0);
+	}
 }
 
 const char *GfxTinyGL::getVideoDeviceName() {
@@ -131,7 +134,7 @@ void GfxTinyGL::positionCamera(const Math::Vector3d &pos, const Math::Vector3d &
 }
 
 void GfxTinyGL::positionCamera(const Math::Vector3d &pos, const Math::Matrix4 &rot) {
-	tglScalef(1.0, 1.0, -1.0);
+	tglScalef(1.0f, 1.0f, -1.0f);
 	_currentPos = pos;
 	_currentRot = rot;
 }
@@ -165,7 +168,7 @@ Math::Matrix4 GfxTinyGL::getProjection() {
 }
 
 void GfxTinyGL::clearScreen() {
-	tglClear(TGL_COLOR_BUFFER_BIT | TGL_DEPTH_BUFFER_BIT | TGL_STENCIL_BUFFER_BIT);
+	tglClear(TGL_COLOR_BUFFER_BIT | TGL_DEPTH_BUFFER_BIT);
 }
 
 void GfxTinyGL::clearDepthBuffer() {
@@ -343,7 +346,6 @@ void GfxTinyGL::getScreenBoundingBox(const EMIModel *model, int *x1, int *y1, in
 
 		for (uint j = 0; j < model->_faces[i]._faceLength * 3; j++) {
 			uint16 index = indices[j];
-
 			Math::Vector3d obj = model->_drawVertices[index];
 			Math::Vector3d win;
 			Math::gluMathProject<TGLfloat, TGLint>(obj, modelView, projection, viewPort, win);
@@ -395,7 +397,7 @@ void GfxTinyGL::getActorScreenBBox(const Actor *actor, Common::Point &p1, Common
 	Math::Matrix4 m = actor->getFinalMatrix();
 	bboxPos = bboxPos + actor->getWorldPos();
 
-	// Set up the coordinate system
+	// Set up the camera coordinate system
 	tglMatrixMode(TGL_MODELVIEW);
 	tglPushMatrix();
 
@@ -449,7 +451,6 @@ void GfxTinyGL::getActorScreenBBox(const Actor *actor, Common::Point &p1, Common
 	tglPopMatrix();
 }
 
-
 void GfxTinyGL::startActorDraw(const Actor *actor) {
 	_currentActor = actor;
 	tglEnable(TGL_TEXTURE_2D);
@@ -550,7 +551,6 @@ void GfxTinyGL::finishActorDraw() {
 }
 
 void GfxTinyGL::drawShadowPlanes() {
-	tglDepthMask(TGL_FALSE);
 	tglPushMatrix();
 
 	if (g_grim->getGameType() == GType_MONKEY4) {
@@ -562,12 +562,14 @@ void GfxTinyGL::drawShadowPlanes() {
 	tglColorMask(TGL_FALSE, TGL_FALSE, TGL_FALSE, TGL_FALSE);
 	tglDepthMask(TGL_FALSE);
 
+	tglClear(TGL_STENCIL_BUFFER_BIT);
 	tglEnable(TGL_STENCIL_TEST);
+	tglStencilFunc(TGL_ALWAYS, 1, 0xff);
+	tglStencilOp(TGL_REPLACE, TGL_REPLACE, TGL_REPLACE);
+
 	tglDisable(TGL_LIGHTING);
 	tglDisable(TGL_TEXTURE_2D);
 	tglColor4f(1.0f, 1.0f, 1.0f, 1.0f);
-
-	_currentShadowArray->planeList.begin();
 	for (SectorListType::iterator i = _currentShadowArray->planeList.begin(); i != _currentShadowArray->planeList.end(); ++i) {
 		Sector *shadowSector = i->sector;
 		tglBegin(TGL_POLYGON);
@@ -576,13 +578,18 @@ void GfxTinyGL::drawShadowPlanes() {
 		}
 		tglEnd();
 	}
-
-	tglDisable(TGL_STENCIL_TEST);
 	tglColorMask(TGL_TRUE, TGL_TRUE, TGL_TRUE, TGL_TRUE);
 
+	tglStencilFunc(TGL_EQUAL, 1, 0xff);
+	tglStencilOp(TGL_KEEP, TGL_KEEP, TGL_KEEP);
+
 	tglPopMatrix();
 }
 
+void GfxTinyGL::setShadow(Shadow *shadow) {
+	_currentShadowArray = shadow;
+}
+
 void GfxTinyGL::setShadowMode() {
 	GfxBase::setShadowMode();
 }
@@ -590,23 +597,10 @@ void GfxTinyGL::setShadowMode() {
 void GfxTinyGL::clearShadowMode() {
 	GfxBase::clearShadowMode();
 
+	tglDisable(TGL_STENCIL_TEST);
 	tglDepthMask(TGL_TRUE);
 }
 
-void GfxTinyGL::set3DMode() {
-	tglMatrixMode(TGL_MODELVIEW);
-	tglEnable(TGL_DEPTH_TEST);
-	tglDepthFunc(_depthFunc);
-}
-
-void GfxTinyGL::setShadow(Shadow *shadow) {
-	_currentShadowArray = shadow;
-	if (shadow)
-		tglDisable(TGL_LIGHTING);
-	else if (g_grim->getGameType() == GType_GRIM)
-		tglEnable(TGL_LIGHTING);
-}
-
 void GfxTinyGL::setShadowColor(byte r, byte g, byte b) {
 	_shadowColorR = r;
 	_shadowColorG = g;
@@ -619,6 +613,12 @@ void GfxTinyGL::getShadowColor(byte *r, byte *g, byte *b) {
 	*b = _shadowColorB;
 }
 
+void GfxTinyGL::set3DMode() {
+	tglMatrixMode(TGL_MODELVIEW);
+	tglEnable(TGL_DEPTH_TEST);
+	tglDepthFunc(_depthFunc);
+}
+
 void GfxTinyGL::drawEMIModelFace(const EMIModel *model, const EMIMeshFace *face) {
 	uint16 *indices = (uint16 *)face->_indexes;
 
@@ -649,7 +649,7 @@ void GfxTinyGL::drawEMIModelFace(const EMIModel *model, const EMIMeshFace *face)
 			byte r = (byte)(model->_colorMap[index].r * lighting.x());
 			byte g = (byte)(model->_colorMap[index].g * lighting.y());
 			byte b = (byte)(model->_colorMap[index].b * lighting.z());
-			byte a = (int)(model->_colorMap[index].a * alpha * _currentActor->getLocalAlpha(index));
+			byte a = (int)(alpha * (model->_meshAlphaMode == Actor::AlphaReplace ? model->_colorMap[index].a * _currentActor->getLocalAlpha(index) : 255.f));
 			tglColor4ub(r, g, b, a);
 		}
 
@@ -762,7 +762,6 @@ void GfxTinyGL::drawSprite(const Sprite *sprite) {
 
 		float halfWidth = sprite->_width / 2;
 		float halfHeight = sprite->_height / 2;
-
 		float vertexX[] = { -1.0f, 1.0f, 1.0f, -1.0f };
 		float vertexY[] = { 1.0f, 1.0f, -1.0f, -1.0f };
 
@@ -1383,6 +1382,7 @@ void GfxTinyGL::drawRectangle(const PrimitiveObject *primitive) {
 		tglVertex2f(x1, y2 + 1);
 		tglEnd();
 	} else {
+		// tglLineWidth(_scaleW); // Not implemented in TinyGL
 		tglBegin(TGL_LINE_LOOP);
 		tglVertex2f(x1, y1);
 		tglVertex2f(x2 + 1, y1);
@@ -1437,7 +1437,7 @@ void GfxTinyGL::drawDimPlane() {
 
 	tglMatrixMode(TGL_PROJECTION);
 	tglLoadIdentity();
-
+	tglOrtho(0, 1.0, 1.0, 0, 0, 1);
 	tglMatrixMode(TGL_MODELVIEW);
 	tglLoadIdentity();
 




More information about the Scummvm-git-logs mailing list