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

aquadran noreply at scummvm.org
Sun Jun 5 19:01:09 UTC 2022


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:
af899c07bf PLAYGROUND3D: Added minimal fog test for tinygl renderer.


Commit: af899c07bfdfac3249c12878cd72c8ed89ca41c7
    https://github.com/scummvm/scummvm/commit/af899c07bfdfac3249c12878cd72c8ed89ca41c7
Author: Paweł Kołodziejski (aquadran at gmail.com)
Date: 2022-06-05T21:01:04+02:00

Commit Message:
PLAYGROUND3D: Added minimal fog test for tinygl renderer.

Changed paths:
    engines/playground3d/gfx.h
    engines/playground3d/gfx_opengl.cpp
    engines/playground3d/gfx_opengl.h
    engines/playground3d/gfx_opengl_shaders.cpp
    engines/playground3d/gfx_opengl_shaders.h
    engines/playground3d/gfx_tinygl.cpp
    engines/playground3d/gfx_tinygl.h
    engines/playground3d/playground3d.cpp
    engines/playground3d/playground3d.h


diff --git a/engines/playground3d/gfx.h b/engines/playground3d/gfx.h
index c4a8f1a2a0f..8b0a0563224 100644
--- a/engines/playground3d/gfx.h
+++ b/engines/playground3d/gfx.h
@@ -69,6 +69,8 @@ public:
 	virtual void drawInViewport() = 0;
 	virtual void drawRgbaTexture() = 0;
 
+	virtual void enableFog(const Math::Vector4d &fogColor) = 0;
+
 protected:
 	OSystem *_system;
 
diff --git a/engines/playground3d/gfx_opengl.cpp b/engines/playground3d/gfx_opengl.cpp
index 8c2b23e4b0a..12fcc63afbb 100644
--- a/engines/playground3d/gfx_opengl.cpp
+++ b/engines/playground3d/gfx_opengl.cpp
@@ -149,6 +149,16 @@ void OpenGLRenderer::setupViewport(int x, int y, int width, int height) {
 	glViewport(x, y, width, height);
 }
 
+void OpenGLRenderer::enableFog(const Math::Vector4d &fogColor) {
+	glFogi(GL_FOG_MODE, GL_EXP);
+	glFogf(GL_FOG_START, 1.0f);
+	glFogf(GL_FOG_END, 1.0f);
+	glFogf(GL_FOG_DENSITY, 0.1f);
+	GLfloat color[4] = { fogColor.x(), fogColor.y(), fogColor.z(), fogColor.w() };
+	glFogfv(GL_FOG_COLOR, color);
+	glEnable(GL_FOG);
+}
+
 void OpenGLRenderer::drawFace(uint face) {
 	glBegin(GL_TRIANGLE_STRIP);
 	for (uint i = 0; i < 4; i++) {
diff --git a/engines/playground3d/gfx_opengl.h b/engines/playground3d/gfx_opengl.h
index 24c7cc341e8..e03231fb0b7 100644
--- a/engines/playground3d/gfx_opengl.h
+++ b/engines/playground3d/gfx_opengl.h
@@ -55,6 +55,8 @@ public:
 	void drawInViewport() override;
 	void drawRgbaTexture() override;
 
+	void enableFog(const Math::Vector4d &fogColor) override;
+
 private:
 	Math::Vector3d _pos;
 	GLuint _textureRgbaId[5];
diff --git a/engines/playground3d/gfx_opengl_shaders.cpp b/engines/playground3d/gfx_opengl_shaders.cpp
index e1e17533ca2..71cafb7d695 100644
--- a/engines/playground3d/gfx_opengl_shaders.cpp
+++ b/engines/playground3d/gfx_opengl_shaders.cpp
@@ -168,6 +168,9 @@ void ShaderRenderer::setupViewport(int x, int y, int width, int height) {
 	glViewport(x, y, width, height);
 }
 
+void ShaderRenderer::enableFog(const Math::Vector4d &fogColor) {
+}
+
 void ShaderRenderer::drawCube(const Math::Vector3d &pos, const Math::Vector3d &roll) {
 	auto rotateMatrix = (Math::Quaternion::fromEuler(roll.x(), roll.y(), roll.z(), Math::EO_XYZ)).inverse().toMatrix();
 	_cubeShader->use();
diff --git a/engines/playground3d/gfx_opengl_shaders.h b/engines/playground3d/gfx_opengl_shaders.h
index 010a918f50a..1ff57e3591d 100644
--- a/engines/playground3d/gfx_opengl_shaders.h
+++ b/engines/playground3d/gfx_opengl_shaders.h
@@ -55,6 +55,8 @@ public:
 	void drawInViewport() override;
 	void drawRgbaTexture() override;
 
+	void enableFog(const Math::Vector4d &fogColor) override;
+
 private:
 	OpenGL::ShaderGL *_cubeShader;
 	OpenGL::ShaderGL *_fadeShader;
diff --git a/engines/playground3d/gfx_tinygl.cpp b/engines/playground3d/gfx_tinygl.cpp
index db196c6d15e..c911fb6b3f8 100644
--- a/engines/playground3d/gfx_tinygl.cpp
+++ b/engines/playground3d/gfx_tinygl.cpp
@@ -177,6 +177,16 @@ void TinyGLRenderer::setupViewport(int x, int y, int width, int height) {
 	tglViewport(x, y, width, height);
 }
 
+void TinyGLRenderer::enableFog(const Math::Vector4d &fogColor) {
+	tglFogi(TGL_FOG_MODE, TGL_EXP);
+	tglFogf(TGL_FOG_START, 1.0f);
+	tglFogf(TGL_FOG_END, 1.0f);
+	tglFogf(TGL_FOG_DENSITY, 0.1f);
+	TGLfloat color[4] = { fogColor.x(), fogColor.y(), fogColor.z(), fogColor.w() };
+	tglFogfv(TGL_FOG_COLOR, color);
+	tglEnable(TGL_FOG);
+}
+
 void TinyGLRenderer::drawFace(uint face) {
 	tglBegin(TGL_TRIANGLE_STRIP);
 	for (uint i = 0; i < 4; i++) {
diff --git a/engines/playground3d/gfx_tinygl.h b/engines/playground3d/gfx_tinygl.h
index 9b58c22bd9c..f38afd257e7 100644
--- a/engines/playground3d/gfx_tinygl.h
+++ b/engines/playground3d/gfx_tinygl.h
@@ -55,6 +55,8 @@ public:
 	void drawInViewport() override;
 	void drawRgbaTexture() override;
 
+	void enableFog(const Math::Vector4d &fogColor) override;
+
 	void flipBuffer() override;
 
 private:
diff --git a/engines/playground3d/playground3d.cpp b/engines/playground3d/playground3d.cpp
index 768dbb38b81..ecd396e0f30 100644
--- a/engines/playground3d/playground3d.cpp
+++ b/engines/playground3d/playground3d.cpp
@@ -55,8 +55,9 @@ bool Playground3dEngine::hasFeature(EngineFeature f) const {
 
 Playground3dEngine::Playground3dEngine(OSystem *syst)
 		: Engine(syst), _system(syst), _gfx(nullptr), _frameLimiter(nullptr),
-		_rotateAngleX(0), _rotateAngleY(0), _rotateAngleZ(0),
-		_clearColor(0.0f, 0.0f, 0.0f, 1.0f), _fade(1.0f), _fadeIn(false),
+		_rotateAngleX(0), _rotateAngleY(0), _rotateAngleZ(0), _fogEnable(false),
+		_clearColor(0.0f, 0.0f, 0.0f, 1.0f), _fogColor(0.0f, 0.0f, 0.0f, 1.0f),
+        _fade(1.0f), _fadeIn(false),
 		_rgbaTexture(nullptr), _rgbTexture(nullptr), _rgb565Texture(nullptr),
 		_rgba5551Texture(nullptr), _rgba4444Texture(nullptr) {
 }
@@ -80,6 +81,11 @@ Common::Error Playground3dEngine::run() {
 	// 4 - moving filled rectangle in viewport
 	// 5 - drawing RGBA pattern texture to check endian correctness
 	int testId = 1;
+	_fogEnable = false;
+
+	if (_fogEnable) {
+		_fogColor = Math::Vector4d(1.0f, 1.0f, 1.0f, 1.0f);
+	}
 
 	switch (testId) {
 		case 1:
@@ -224,6 +230,9 @@ void Playground3dEngine::drawFrame(int testId) {
 
 	switch (testId) {
 		case 1:
+			if (_fogEnable) {
+				_gfx->enableFog(_fogColor);
+			}
 			drawAndRotateCube();
 			break;
 		case 2:
diff --git a/engines/playground3d/playground3d.h b/engines/playground3d/playground3d.h
index aa6e174c0c5..a5bd7661fff 100644
--- a/engines/playground3d/playground3d.h
+++ b/engines/playground3d/playground3d.h
@@ -50,8 +50,10 @@ private:
 	Renderer *_gfx;
 	Graphics::FrameLimiter *_frameLimiter;
 	Math::Vector4d _clearColor;
+	Math::Vector4d _fogColor;
 	float _fade;
 	bool _fadeIn;
+	bool _fogEnable;
 	Graphics::Surface *_rgbaTexture;
 	Graphics::Surface *_rgbTexture;
 	Graphics::Surface *_rgb565Texture;




More information about the Scummvm-git-logs mailing list