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

aquadran aquadran at gmail.com
Tue Oct 26 20:02:43 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:
e7ef9718a6 PLAYGROUND3D: Added polygon depth offset test


Commit: e7ef9718a60635a132f7fa4277af1ced13384f71
    https://github.com/scummvm/scummvm/commit/e7ef9718a60635a132f7fa4277af1ced13384f71
Author: Paweł Kołodziejski (aquadran at gmail.com)
Date: 2021-10-26T22:02:39+02:00

Commit Message:
PLAYGROUND3D: Added polygon depth offset test

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 055a85a0b4..836e415347 100644
--- a/engines/playground3d/gfx.h
+++ b/engines/playground3d/gfx.h
@@ -55,6 +55,7 @@ public:
 	void computeScreenViewport();
 
 	virtual void drawCube(const Math::Vector3d &pos, const Math::Vector3d &roll) = 0;
+	virtual void drawPolyOffsetTest(const Math::Vector3d &pos, const Math::Vector3d &roll) = 0;
 
 protected:
 	OSystem *_system;
diff --git a/engines/playground3d/gfx_opengl.cpp b/engines/playground3d/gfx_opengl.cpp
index 282336ff64..1532c34718 100644
--- a/engines/playground3d/gfx_opengl.cpp
+++ b/engines/playground3d/gfx_opengl.cpp
@@ -99,6 +99,37 @@ void OpenGLRenderer::drawCube(const Math::Vector3d &pos, const Math::Vector3d &r
 	}
 }
 
+void OpenGLRenderer::drawPolyOffsetTest(const Math::Vector3d &pos, const Math::Vector3d &roll) {
+	Common::Rect vp = viewport();
+	glViewport(vp.left, _system->getHeight() - vp.top - vp.height(), vp.width(), vp.height());
+
+	glMatrixMode(GL_PROJECTION);
+	glLoadMatrixf(_projectionMatrix.getData());
+
+	glMatrixMode(GL_MODELVIEW);
+	glLoadMatrixf(_modelViewMatrix.getData());
+
+	glTranslatef(pos.x(), pos.y(), pos.z());
+	glRotatef(roll.y(), 0.0f, 1.0f, 0.0f);
+
+	glColor3f(0.0f, 1.0f, 0.0f);
+	glBegin(GL_TRIANGLES);
+	glVertex3f(-1.0f,  1.0, 0.0f);
+	glVertex3f( 1.0f,  1.0, 0.0f);
+	glVertex3f( 0.0f, -1.0, 0.0f);
+	glEnd();
+
+	glPolygonOffset(-1.0f, 0.0f);
+	glEnable(GL_POLYGON_OFFSET_FILL);
+	glColor3f(1.0f, 1.0f, 1.0f);
+	glBegin(GL_TRIANGLES);
+	glVertex3f(-0.5f,  0.5, 0.0f);
+	glVertex3f( 0.5f,  0.5, 0.0f);
+	glVertex3f( 0.0f, -0.5, 0.0f);
+	glEnd();
+	glDisable(GL_POLYGON_OFFSET_FILL);
+}
+
 } // End of namespace Playground3d
 
 #endif
diff --git a/engines/playground3d/gfx_opengl.h b/engines/playground3d/gfx_opengl.h
index 1fad289568..b2dc406c39 100644
--- a/engines/playground3d/gfx_opengl.h
+++ b/engines/playground3d/gfx_opengl.h
@@ -44,6 +44,7 @@ public:
 	virtual void clear() override;
 
 	virtual void drawCube(const Math::Vector3d &pos, const Math::Vector3d &roll) override;
+	virtual void drawPolyOffsetTest(const Math::Vector3d &pos, const Math::Vector3d &roll) override;
 
 private:
 	void drawFace(uint face);
diff --git a/engines/playground3d/gfx_opengl_shaders.cpp b/engines/playground3d/gfx_opengl_shaders.cpp
index a1c94ba589..20cf813397 100644
--- a/engines/playground3d/gfx_opengl_shaders.cpp
+++ b/engines/playground3d/gfx_opengl_shaders.cpp
@@ -96,6 +96,10 @@ void ShaderRenderer::drawCube(const Math::Vector3d &pos, const Math::Vector3d &r
 	glDrawArrays(GL_TRIANGLE_STRIP, 20, 4);
 }
 
+void ShaderRenderer::drawPolyOffsetTest(const Math::Vector3d &pos, const Math::Vector3d &roll) {
+	error("Polygon offset test not implemented yet");
+}
+
 } // End of namespace Playground3d
 
 #endif
diff --git a/engines/playground3d/gfx_opengl_shaders.h b/engines/playground3d/gfx_opengl_shaders.h
index cc34b35162..9ad655d0ec 100644
--- a/engines/playground3d/gfx_opengl_shaders.h
+++ b/engines/playground3d/gfx_opengl_shaders.h
@@ -44,6 +44,7 @@ public:
 	virtual void clear() override;
 
 	virtual void drawCube(const Math::Vector3d &pos, const Math::Vector3d &roll) override;
+	virtual void drawPolyOffsetTest(const Math::Vector3d &pos, const Math::Vector3d &roll) override;
 
 private:
 	OpenGL::ShaderGL *_cubeShader;
diff --git a/engines/playground3d/gfx_tinygl.cpp b/engines/playground3d/gfx_tinygl.cpp
index cf29600819..dfc4960a01 100644
--- a/engines/playground3d/gfx_tinygl.cpp
+++ b/engines/playground3d/gfx_tinygl.cpp
@@ -101,6 +101,37 @@ void TinyGLRenderer::drawCube(const Math::Vector3d &pos, const Math::Vector3d &r
 	}
 }
 
+void TinyGLRenderer::drawPolyOffsetTest(const Math::Vector3d &pos, const Math::Vector3d &roll) {
+	Common::Rect vp = viewport();
+	tglViewport(vp.left, _system->getHeight() - vp.top - vp.height(), vp.width(), vp.height());
+
+	tglMatrixMode(TGL_PROJECTION);
+	tglLoadMatrixf(_projectionMatrix.getData());
+
+	tglMatrixMode(TGL_MODELVIEW);
+	tglLoadMatrixf(_modelViewMatrix.getData());
+
+	tglTranslatef(pos.x(), pos.y(), pos.z());
+	tglRotatef(roll.y(), 0.0f, 1.0f, 0.0f);
+
+	tglColor3f(0.0f, 1.0f, 0.0f);
+	tglBegin(TGL_TRIANGLES);
+	tglVertex3f(-1.0f,  1.0, 0.0f);
+	tglVertex3f( 1.0f,  1.0, 0.0f);
+	tglVertex3f( 0.0f, -1.0, 0.0f);
+	tglEnd();
+
+	tglPolygonOffset(-1.0f, 0.0f);
+	tglEnable(TGL_POLYGON_OFFSET_FILL);
+	tglColor3f(1.0f, 1.0f, 1.0f);
+	tglBegin(TGL_TRIANGLES);
+	tglVertex3f(-0.5f,  0.5, 0.0f);
+	tglVertex3f( 0.5f,  0.5, 0.0f);
+	tglVertex3f( 0.0f, -0.5, 0.0f);
+	tglEnd();
+	tglDisable(TGL_POLYGON_OFFSET_FILL);
+}
+
 void TinyGLRenderer::flipBuffer() {
 	TinyGL::tglPresentBuffer();
 	g_system->copyRectToScreen(_fb->getPixelBuffer(), _fb->linesize, 0, 0, _fb->xsize, _fb->ysize);
diff --git a/engines/playground3d/gfx_tinygl.h b/engines/playground3d/gfx_tinygl.h
index 4e2660ead5..0b435192ee 100644
--- a/engines/playground3d/gfx_tinygl.h
+++ b/engines/playground3d/gfx_tinygl.h
@@ -44,6 +44,7 @@ public:
 	virtual void clear() override;
 
 	virtual void drawCube(const Math::Vector3d &pos, const Math::Vector3d &roll) override;
+	virtual void drawPolyOffsetTest(const Math::Vector3d &pos, const Math::Vector3d &roll) override;
 
 	virtual void flipBuffer() override;
 
diff --git a/engines/playground3d/playground3d.cpp b/engines/playground3d/playground3d.cpp
index 2ad0aa088b..68184553bf 100644
--- a/engines/playground3d/playground3d.cpp
+++ b/engines/playground3d/playground3d.cpp
@@ -46,7 +46,7 @@ bool Playground3dEngine::hasFeature(EngineFeature f) const {
 
 Playground3dEngine::Playground3dEngine(OSystem *syst)
 		: Engine(syst), _system(syst), _frameLimiter(0),
-		_rotateAngleX(45), _rotateAngleY(45), _rotateAngleZ(10) {
+		_rotateAngleX(0), _rotateAngleY(0), _rotateAngleZ(0) {
 }
 
 Playground3dEngine::~Playground3dEngine() {
@@ -63,9 +63,23 @@ Common::Error Playground3dEngine::run() {
 
 	_system->showMouse(true);
 
+	// 1 - rotated colorfull cube
+	// 2 - rotated two traingles with depth offset
+	int testId = 1;
+
+	switch (testId) {
+		case 1:
+			_rotateAngleX = 45, _rotateAngleY = 45, _rotateAngleZ = 10;
+			break;
+		case 2:
+			break;
+		default:
+			assert(false);
+	}
+
 	while (!shouldQuit()) {
 		processInput();
-		drawFrame();
+		drawFrame(testId);
 	}
 
 	_system->showMouse(false);
@@ -97,7 +111,15 @@ void Playground3dEngine::drawAndRotateCube() {
 		_rotateAngleZ = 0;
 }
 
-void Playground3dEngine::drawFrame() {
+void Playground3dEngine::drawPolyOffsetTest() {
+	Math::Vector3d pos = Math::Vector3d(0.0f, 0.0f, 6.0f);
+	_gfx->drawPolyOffsetTest(pos, Math::Vector3d(0, _rotateAngleY, 0));
+	_rotateAngleY += 0.10;
+	if (_rotateAngleY >= 360)
+		_rotateAngleY = 0;
+}
+
+void Playground3dEngine::drawFrame(int testId) {
 	_gfx->clear();
 
 	float pitch = 0.0f;
@@ -105,7 +127,16 @@ void Playground3dEngine::drawFrame() {
 	float fov = 45.0f;
 	_gfx->setupCameraPerspective(pitch, heading, fov);
 
-	drawAndRotateCube();
+	switch (testId) {
+		case 1:
+			drawAndRotateCube();
+			break;
+		case 2:
+			drawPolyOffsetTest();
+			break;
+		default:
+			assert(false);
+	}
 
 	_gfx->flipBuffer();
 
diff --git a/engines/playground3d/playground3d.h b/engines/playground3d/playground3d.h
index d9c7bd9bec..8a23f5a961 100644
--- a/engines/playground3d/playground3d.h
+++ b/engines/playground3d/playground3d.h
@@ -43,7 +43,7 @@ public:
 
 	void processInput();
 
-	void drawFrame();
+	void drawFrame(int testId);
 
 private:
 	OSystem *_system;
@@ -53,6 +53,7 @@ private:
 	float _rotateAngleX, _rotateAngleY, _rotateAngleZ;
 
 	void drawAndRotateCube();
+	void drawPolyOffsetTest();
 };
 
 } // End of namespace Playground3d




More information about the Scummvm-git-logs mailing list