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

aquadran noreply at scummvm.org
Mon Dec 20 19:15:22 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:
b4f8414a44 STARK: Ported opengl minor code changes


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

Commit Message:
STARK: Ported opengl minor code changes

Changed paths:
    engines/stark/gfx/openglactor.cpp
    engines/stark/gfx/openglactor.h
    engines/stark/gfx/openglprop.cpp
    engines/stark/gfx/openglprop.h
    engines/stark/gfx/openglsactor.cpp
    engines/stark/gfx/openglsurface.h


diff --git a/engines/stark/gfx/openglactor.cpp b/engines/stark/gfx/openglactor.cpp
index de4b008584..2220e5728c 100644
--- a/engines/stark/gfx/openglactor.cpp
+++ b/engines/stark/gfx/openglactor.cpp
@@ -58,9 +58,9 @@ void OpenGLActorRenderer::render(const Math::Vector3d &position, float direction
 	_model->updateBoundingBox();
 
 	bool drawShadow = false;
-	if (_castsShadow
-			&& StarkScene->shouldRenderShadows()
-			&& StarkSettings->getBoolSetting(Settings::kShadow)) {
+	if (_castsShadow &&
+	    StarkScene->shouldRenderShadows() &&
+	    StarkSettings->getBoolSetting(Settings::kShadow)) {
 		drawShadow = true;
 	}
 	Math::Vector3d lightDirection;
@@ -101,8 +101,6 @@ void OpenGLActorRenderer::render(const Math::Vector3d &position, float direction
 		lightDirection = getShadowLightDirection(lights, position, modelInverse.getRotation());
 	}
 
-	glEnable(GL_TEXTURE_2D);
-
 	Common::Array<Face *> faces = _model->getFaces();
 	Common::Array<Material *> mats = _model->getMaterials();
 	const Common::Array<BoneNode *> &bones = _model->getBones();
@@ -116,17 +114,22 @@ void OpenGLActorRenderer::render(const Math::Vector3d &position, float direction
 		const Material *material = mats[(*face)->materialId];
 		Math::Vector3d color;
 		const Gfx::Texture *tex = resolveTexture(material);
+		if (tex) {
+			tex->bind();
+			glEnable(GL_TEXTURE_2D);
+		} else {
+			glBindTexture(GL_TEXTURE_2D, 0);
+			glDisable(GL_TEXTURE_2D);
+		}
 		auto vertexIndices = _faceEBO[*face];
 		auto numVertexIndices = (*face)->vertexIndices.size();
 		for (uint32 i = 0; i < numVertexIndices; i++) {
 			if (tex) {
-				tex->bind();
 				if (_gfx->computeLightsEnabled())
 					color = Math::Vector3d(1.0f, 1.0f, 1.0f);
 				else
 					glColor3f(1.0f, 1.0f, 1.0f);
 			} else {
-				glBindTexture(GL_TEXTURE_2D, 0);
 				if (_gfx->computeLightsEnabled())
 					color = Math::Vector3d(material->r, material->g, material->b);
 				else
@@ -139,19 +142,19 @@ void OpenGLActorRenderer::render(const Math::Vector3d &position, float direction
 			Math::Vector3d position1 = Math::Vector3d(vertex.pos1x, vertex.pos1y, vertex.pos1z);
 			Math::Vector3d position2 = Math::Vector3d(vertex.pos2x, vertex.pos2y, vertex.pos2z);
 			Math::Vector3d bone1Position = Math::Vector3d(bones[bone1]->_animPos.x(),
-														  bones[bone1]->_animPos.y(),
-														  bones[bone1]->_animPos.z());
+			                                              bones[bone1]->_animPos.y(),
+			                                              bones[bone1]->_animPos.z());
 			Math::Vector3d bone2Position = Math::Vector3d(bones[bone2]->_animPos.x(),
-														  bones[bone2]->_animPos.y(),
-														  bones[bone2]->_animPos.z());
+			                                              bones[bone2]->_animPos.y(),
+			                                              bones[bone2]->_animPos.z());
 			Math::Quaternion bone1Rotation = Math::Quaternion(bones[bone1]->_animRot.x(),
-														  bones[bone1]->_animRot.y(),
-														  bones[bone1]->_animRot.z(),
-														  bones[bone1]->_animRot.w());
+			                                                  bones[bone1]->_animRot.y(),
+			                                                  bones[bone1]->_animRot.z(),
+			                                                  bones[bone1]->_animRot.w());
 			Math::Quaternion bone2Rotation = Math::Quaternion(bones[bone2]->_animRot.x(),
-														  bones[bone2]->_animRot.y(),
-														  bones[bone2]->_animRot.z(),
-														  bones[bone2]->_animRot.w());
+			                                                  bones[bone2]->_animRot.y(),
+			                                                  bones[bone2]->_animRot.z(),
+			                                                  bones[bone2]->_animRot.w());
 			float boneWeight = vertex.boneWeight;
 			Math::Vector3d normal = Math::Vector3d(vertex.normalx, vertex.normaly, vertex.normalz);
 
@@ -167,9 +170,9 @@ void OpenGLActorRenderer::render(const Math::Vector3d &position, float direction
 			Math::Vector4d modelEyePosition;
 			if (_gfx->computeLightsEnabled()) {
 				modelEyePosition = modelViewMatrix * Math::Vector4d(modelPosition.x(),
-																		       modelPosition.y(),
-																		       modelPosition.z(),
-																		       1.0);
+				                                                    modelPosition.y(),
+				                                                    modelPosition.z(),
+				                                                    1.0);
 			}
 			// Compute the vertex normal in eye-space
 			Math::Vector3d n1 = normal;
@@ -302,7 +305,6 @@ void OpenGLActorRenderer::render(const Math::Vector3d &position, float direction
 
 		if (!_gfx->computeLightsEnabled())
 			glEnable(GL_LIGHTING);
-		glEnable(GL_TEXTURE_2D);
 		glDisable(GL_BLEND);
 		glDisable(GL_STENCIL_TEST);
 	}
@@ -363,8 +365,8 @@ uint32 *OpenGLActorRenderer::createFaceEBO(const Face *face) {
 	return indices;
 }
 
-Math::Vector3d OpenGLActorRenderer::getShadowLightDirection(const LightEntryArray &lights,
-		const Math::Vector3d &actorPosition, Math::Matrix3 worldToModelRot) {
+Math::Vector3d OpenGLActorRenderer::getShadowLightDirection(const LightEntryArray &lights, const Math::Vector3d &actorPosition,
+                                                            Math::Matrix3 worldToModelRot) {
 	Math::Vector3d sumDirection;
 	bool hasLight = false;
 
@@ -418,8 +420,8 @@ Math::Vector3d OpenGLActorRenderer::getShadowLightDirection(const LightEntryArra
 	return worldToModelRot * sumDirection;
 }
 
-bool OpenGLActorRenderer::getPointLightContribution(LightEntry *light,
-		const Math::Vector3d &actorPosition, Math::Vector3d &direction, float weight) {
+bool OpenGLActorRenderer::getPointLightContribution(LightEntry *light, const Math::Vector3d &actorPosition,
+                                                    Math::Vector3d &direction, float weight) {
 	float distance = light->position.getDistanceTo(actorPosition);
 
 	if (distance > light->falloffFar) {
@@ -464,14 +466,14 @@ bool OpenGLActorRenderer::getDirectionalLightContribution(LightEntry *light, Mat
 	return true;
 }
 
-bool OpenGLActorRenderer::getSpotLightContribution(LightEntry *light,
-		const Math::Vector3d &actorPosition, Math::Vector3d &direction) {
+bool OpenGLActorRenderer::getSpotLightContribution(LightEntry *light, const Math::Vector3d &actorPosition,
+                                                   Math::Vector3d &direction) {
 	Math::Vector3d lightToActor = actorPosition - light->position;
 	lightToActor.normalize();
 
 	float cosAngle = MAX(0.0f, lightToActor.dotProduct(light->direction));
 	float cone = (cosAngle - light->innerConeAngle.getCosine()) /
-			MAX(0.001f, light->outerConeAngle.getCosine() - light->innerConeAngle.getCosine());
+	             MAX(0.001f, light->outerConeAngle.getCosine() - light->innerConeAngle.getCosine());
 	cone = CLIP(cone, 0.0f, 1.0f);
 
 	if (cone <= 0) {
diff --git a/engines/stark/gfx/openglactor.h b/engines/stark/gfx/openglactor.h
index a837f0bfcd..f861bb403f 100644
--- a/engines/stark/gfx/openglactor.h
+++ b/engines/stark/gfx/openglactor.h
@@ -39,8 +39,6 @@ namespace Gfx {
 
 class OpenGLDriver;
 
-#include "common/pack-start.h"
-
 struct _ActorVertex {
 	float pos1x;
 	float pos1y;
@@ -68,11 +66,9 @@ struct _ActorVertex {
 	float r;
 	float g;
 	float b;
-} PACKED_STRUCT;
+};
 typedef _ActorVertex ActorVertex;
 
-#include "common/pack-end.h"
-
 class OpenGLActorRenderer : public VisualActor {
 public:
 	OpenGLActorRenderer(OpenGLDriver *gfx);
diff --git a/engines/stark/gfx/openglprop.cpp b/engines/stark/gfx/openglprop.cpp
index ba9539f2f7..327ca55bdf 100644
--- a/engines/stark/gfx/openglprop.cpp
+++ b/engines/stark/gfx/openglprop.cpp
@@ -86,6 +86,13 @@ void OpenGLPropRenderer::render(const Math::Vector3d &position, float direction,
 		const Material &material = materials[face->materialId];
 		Math::Vector3d color;
 		const Gfx::Texture *tex = _texture->getTexture(material.texture);
+		if (tex) {
+			tex->bind();
+			glEnable(GL_TEXTURE_2D);
+		} else {
+			glBindTexture(GL_TEXTURE_2D, 0);
+			glDisable(GL_TEXTURE_2D);
+		}
 		auto vertexIndices = _faceEBO[face];
 		auto numVertexIndices = (face)->vertexIndices.size();
 		if (!_gfx->computeLightsEnabled()) {
@@ -98,7 +105,6 @@ void OpenGLPropRenderer::render(const Math::Vector3d &position, float direction,
 			uint32 index = vertexIndices[i];
 			auto vertex = _faceVBO[index];
 			if (tex) {
-				tex->bind();
 				if (_gfx->computeLightsEnabled())
 					color = Math::Vector3d(1.0f, 1.0f, 1.0f);
 				else
@@ -111,7 +117,6 @@ void OpenGLPropRenderer::render(const Math::Vector3d &position, float direction,
 					vertex.texT = 1.0f - vertex.stexT;
 				}
 			} else {
-				glBindTexture(GL_TEXTURE_2D, 0);
 				if (_gfx->computeLightsEnabled())
 					color = Math::Vector3d(material.r, material.g, material.b);
 				else
diff --git a/engines/stark/gfx/openglprop.h b/engines/stark/gfx/openglprop.h
index 0ebf32081c..cd578d2e0d 100644
--- a/engines/stark/gfx/openglprop.h
+++ b/engines/stark/gfx/openglprop.h
@@ -40,8 +40,6 @@ namespace Gfx {
 
 class Driver;
 
-#include "common/pack-start.h"
-
 struct _PropVertex {
 	float x;
 	float y;
@@ -56,11 +54,9 @@ struct _PropVertex {
 	float r;
 	float g;
 	float b;
-} PACKED_STRUCT;
+};
 typedef _PropVertex PropVertex;
 
-#include "common/pack-end.h"
-
 class OpenGLPropRenderer : public VisualProp {
 public:
 	explicit OpenGLPropRenderer(OpenGLDriver *gfx);
diff --git a/engines/stark/gfx/openglsactor.cpp b/engines/stark/gfx/openglsactor.cpp
index 31bafb69dd..78f07713d9 100644
--- a/engines/stark/gfx/openglsactor.cpp
+++ b/engines/stark/gfx/openglsactor.cpp
@@ -118,9 +118,9 @@ void OpenGLSActorRenderer::render(const Math::Vector3d &position, float directio
 
 	_shader->unbind();
 
-	if (_castsShadow
-	        && StarkScene->shouldRenderShadows()
-	        && StarkSettings->getBoolSetting(Settings::kShadow)) {
+	if (_castsShadow &&
+	    StarkScene->shouldRenderShadows() &&
+	    StarkSettings->getBoolSetting(Settings::kShadow)) {
 		glEnable(GL_BLEND);
 		glEnable(GL_STENCIL_TEST);
 
@@ -307,8 +307,8 @@ void OpenGLSActorRenderer::setLightArrayUniform(const LightEntryArray &lights) {
 	}
 }
 
-void OpenGLSActorRenderer::setShadowUniform(const LightEntryArray &lights,
-		const Math::Vector3d &actorPosition, Math::Matrix3 worldToModelRot) {
+void OpenGLSActorRenderer::setShadowUniform(const LightEntryArray &lights, const Math::Vector3d &actorPosition,
+                                            Math::Matrix3 worldToModelRot) {
 	Math::Vector3d sumDirection;
 	bool hasLight = false;
 
@@ -363,8 +363,8 @@ void OpenGLSActorRenderer::setShadowUniform(const LightEntryArray &lights,
 	_shadowShader->setUniform("lightDirection", sumDirection);
 }
 
-bool OpenGLSActorRenderer::getPointLightContribution(LightEntry *light,
-		const Math::Vector3d &actorPosition, Math::Vector3d &direction, float weight) {
+bool OpenGLSActorRenderer::getPointLightContribution(LightEntry *light, const Math::Vector3d &actorPosition,
+                                                     Math::Vector3d &direction, float weight) {
 	float distance = light->position.getDistanceTo(actorPosition);
 
 	if (distance > light->falloffFar) {
@@ -409,14 +409,14 @@ bool OpenGLSActorRenderer::getDirectionalLightContribution(LightEntry *light, Ma
 	return true;
 }
 
-bool OpenGLSActorRenderer::getSpotLightContribution(LightEntry *light,
-		const Math::Vector3d &actorPosition, Math::Vector3d &direction) {
+bool OpenGLSActorRenderer::getSpotLightContribution(LightEntry *light, const Math::Vector3d &actorPosition,
+                                                    Math::Vector3d &direction) {
 	Math::Vector3d lightToActor = actorPosition - light->position;
 	lightToActor.normalize();
 
 	float cosAngle = MAX(0.0f, lightToActor.dotProduct(light->direction));
 	float cone = (cosAngle - light->innerConeAngle.getCosine()) /
-			MAX(0.001f, light->outerConeAngle.getCosine() - light->innerConeAngle.getCosine());
+	             MAX(0.001f, light->outerConeAngle.getCosine() - light->innerConeAngle.getCosine());
 	cone = CLIP(cone, 0.0f, 1.0f);
 
 	if (cone <= 0) {
diff --git a/engines/stark/gfx/openglsurface.h b/engines/stark/gfx/openglsurface.h
index 427b6fa9cf..f61c618d31 100644
--- a/engines/stark/gfx/openglsurface.h
+++ b/engines/stark/gfx/openglsurface.h
@@ -36,16 +36,12 @@ namespace Gfx {
 class OpenGLDriver;
 class Texture;
 
-#include "common/pack-start.h"
-
 struct _SurfaceVertex {
 	float x;
 	float y;
-} PACKED_STRUCT;
+};
 typedef _SurfaceVertex SurfaceVertex;
 
-#include "common/pack-end.h"
-
 /**
  * An programmable pipeline OpenGL surface renderer
  */




More information about the Scummvm-git-logs mailing list