[Scummvm-git-logs] scummvm master -> 0c5e0912154ae1ccdb23dd2fc8fe22e582678a33

aquadran aquadran at gmail.com
Mon Nov 8 08:00:08 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:
0c5e091215 PLAYGROUND3D: Added viewport test


Commit: 0c5e0912154ae1ccdb23dd2fc8fe22e582678a33
    https://github.com/scummvm/scummvm/commit/0c5e0912154ae1ccdb23dd2fc8fe22e582678a33
Author: Paweł Kołodziejski (aquadran at gmail.com)
Date: 2021-11-08T09:00:01+01:00

Commit Message:
PLAYGROUND3D: Added viewport 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 a6ced749ab..203d8ffd35 100644
--- a/engines/playground3d/gfx.h
+++ b/engines/playground3d/gfx.h
@@ -54,9 +54,11 @@ public:
 
 	void computeScreenViewport();
 
+	virtual void setupViewport(int x, int y, int width, int height) = 0;
 	virtual void drawCube(const Math::Vector3d &pos, const Math::Vector3d &roll) = 0;
 	virtual void drawPolyOffsetTest(const Math::Vector3d &pos, const Math::Vector3d &roll) = 0;
 	virtual void dimRegionInOut(float fade) = 0;
+	virtual void drawInViewport() = 0;
 
 protected:
 	OSystem *_system;
diff --git a/engines/playground3d/gfx_opengl.cpp b/engines/playground3d/gfx_opengl.cpp
index e7044bb2b3..c7c75bff84 100644
--- a/engines/playground3d/gfx_opengl.cpp
+++ b/engines/playground3d/gfx_opengl.cpp
@@ -41,6 +41,14 @@ static const GLfloat dimRegionVertices[] = {
 	 0.5f, -0.5f,
 };
 
+static const GLfloat boxVertices[] = {
+	//  X      Y
+	-1.0f,  1.0f,
+	 1.0f,  1.0f,
+	-1.0f, -1.0f,
+	 1.0f, -1.0f,
+};
+
 Renderer *CreateGfxOpenGL(OSystem *system) {
 	return new OpenGLRenderer(system);
 }
@@ -78,6 +86,10 @@ void OpenGLRenderer::clear(const Math::Vector4d &clearColor) {
 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 }
 
+void OpenGLRenderer::setupViewport(int x, int y, int width, int height) {
+	glViewport(x, y, width, height);
+}
+
 void OpenGLRenderer::drawFace(uint face) {
 	glBegin(GL_TRIANGLE_STRIP);
 	for (uint i = 0; i < 4; i++) {
@@ -89,9 +101,6 @@ void OpenGLRenderer::drawFace(uint face) {
 }
 
 void OpenGLRenderer::drawCube(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());
 
@@ -109,9 +118,6 @@ 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());
 
@@ -140,9 +146,6 @@ void OpenGLRenderer::drawPolyOffsetTest(const Math::Vector3d &pos, const Math::V
 }
 
 void OpenGLRenderer::dimRegionInOut(float fade) {
-	Common::Rect vp = viewport();
-	glViewport(vp.left, _system->getHeight() - vp.top - vp.height(), vp.width(), vp.height());
-
 	glMatrixMode(GL_PROJECTION);
 	glPushMatrix();
 	glLoadIdentity();
@@ -158,7 +161,7 @@ void OpenGLRenderer::dimRegionInOut(float fade) {
 
 	glColor4f(0.0f, 0.0f, 0.0f, 1.0f - fade);
 	glEnableClientState(GL_VERTEX_ARRAY);
-	glVertexPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), &dimRegionVertices[0]);
+	glVertexPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), dimRegionVertices);
 	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
 	glDisableClientState(GL_VERTEX_ARRAY);
 
@@ -169,6 +172,59 @@ void OpenGLRenderer::dimRegionInOut(float fade) {
 	glPopMatrix();
 }
 
+void OpenGLRenderer::drawInViewport() {
+	static GLfloat box2Vertices[] = {
+		//  X      Y
+		-0.1f,  0.1f,
+		 0.1f,  0.1f,
+		-0.1f, -0.1f,
+		 0.1f, -0.1f,
+	};
+	glMatrixMode(GL_PROJECTION);
+	glPushMatrix();
+	glLoadIdentity();
+
+	glMatrixMode(GL_MODELVIEW);
+	glPushMatrix();
+	glLoadIdentity();
+
+	glEnable(GL_BLEND);
+	glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+	glDisable(GL_DEPTH_TEST);
+	glDepthMask(GL_FALSE);
+
+	glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
+	glEnableClientState(GL_VERTEX_ARRAY);
+	glVertexPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), &boxVertices[0]);
+	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+	glDisableClientState(GL_VERTEX_ARRAY);
+
+	glPushMatrix();
+	_pos.x() += 0.01;
+	_pos.y() += 0.01;
+	if (_pos.x() >= 1.0f) {
+		_pos.x() = -1.0;
+		_pos.y() = -1.0;
+	}
+	glTranslatef(_pos.x(), _pos.y(), 0);
+
+	glPolygonOffset(-1.0f, 0.0f);
+	glEnable(GL_POLYGON_OFFSET_FILL);
+	glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
+	glEnableClientState(GL_VERTEX_ARRAY);
+	glVertexPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), &box2Vertices[0]);
+	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+	glDisableClientState(GL_VERTEX_ARRAY);
+	glDisable(GL_POLYGON_OFFSET_FILL);
+
+	glMatrixMode(GL_MODELVIEW);
+	glPopMatrix();
+	glPopMatrix();
+
+	glMatrixMode(GL_PROJECTION);
+	glPopMatrix();
+}
+
 } // End of namespace Playground3d
 
 #endif
diff --git a/engines/playground3d/gfx_opengl.h b/engines/playground3d/gfx_opengl.h
index f8a9fd6d60..9816bc63a0 100644
--- a/engines/playground3d/gfx_opengl.h
+++ b/engines/playground3d/gfx_opengl.h
@@ -43,11 +43,15 @@ public:
 
 	virtual void clear(const Math::Vector4d &clearColor) override;
 
+	virtual void setupViewport(int x, int y, int width, int height) 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 dimRegionInOut(float fade) override;
+	virtual void drawInViewport() override;
 
 private:
+	Math::Vector3d _pos;
+
 	void drawFace(uint face);
 };
 
diff --git a/engines/playground3d/gfx_opengl_shaders.cpp b/engines/playground3d/gfx_opengl_shaders.cpp
index bdea48e9a5..ff920946a5 100644
--- a/engines/playground3d/gfx_opengl_shaders.cpp
+++ b/engines/playground3d/gfx_opengl_shaders.cpp
@@ -94,10 +94,11 @@ void ShaderRenderer::clear(const Math::Vector4d &clearColor) {
 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 }
 
-void ShaderRenderer::drawCube(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());
+void ShaderRenderer::setupViewport(int x, int y, int width, int height) {
+	glViewport(x, y, width, height);
+}
 
+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();
 	_cubeShader->setUniform("textured", false);
@@ -118,9 +119,6 @@ void ShaderRenderer::drawPolyOffsetTest(const Math::Vector3d &pos, const Math::V
 }
 
 void ShaderRenderer::dimRegionInOut(float fade) {
-	Common::Rect vp = viewport();
-	glViewport(vp.left, _system->getHeight() - vp.top - vp.height(), vp.width(), vp.height());
-
 	glEnable(GL_BLEND);
 	glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
 	glDisable(GL_DEPTH_TEST);
@@ -132,6 +130,10 @@ void ShaderRenderer::dimRegionInOut(float fade) {
 	_fadeShader->unbind();
 }
 
+void ShaderRenderer::drawInViewport() {
+	// TODO
+}
+
 } // End of namespace Playground3d
 
 #endif
diff --git a/engines/playground3d/gfx_opengl_shaders.h b/engines/playground3d/gfx_opengl_shaders.h
index ff6dd2ab47..3b12277b4c 100644
--- a/engines/playground3d/gfx_opengl_shaders.h
+++ b/engines/playground3d/gfx_opengl_shaders.h
@@ -43,9 +43,11 @@ public:
 
 	virtual void clear(const Math::Vector4d &clearColor) override;
 
+	virtual void setupViewport(int x, int y, int width, int height) 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 dimRegionInOut(float fade) override;
+	virtual void drawInViewport() override;
 
 private:
 	OpenGL::ShaderGL *_cubeShader;
diff --git a/engines/playground3d/gfx_tinygl.cpp b/engines/playground3d/gfx_tinygl.cpp
index a4ed0ec92a..6b14821572 100644
--- a/engines/playground3d/gfx_tinygl.cpp
+++ b/engines/playground3d/gfx_tinygl.cpp
@@ -47,6 +47,14 @@ static const TGLuint dimRegionIndices[] = {
 	0, 1, 2, 3
 };
 
+static const TGLfloat boxVertices[] = {
+	//  X      Y
+	-1.0f,  1.0f,
+	 1.0f,  1.0f,
+	-1.0f, -1.0f,
+	 1.0f, -1.0f,
+};
+
 Renderer *CreateGfxTinyGL(OSystem *system) {
 	return new TinyGLRenderer(system);
 }
@@ -66,7 +74,7 @@ void TinyGLRenderer::init() {
 
 	_fb = new TinyGL::FrameBuffer(kOriginalWidth, kOriginalHeight, g_system->getScreenFormat());
 	TinyGL::glInit(_fb, 512);
-	tglEnableDirtyRects(ConfMan.getBool("dirtyrects"));
+	tglEnableDirtyRects(false/*ConfMan.getBool("dirtyrects")*/);
 
 	tglMatrixMode(TGL_PROJECTION);
 	tglLoadIdentity();
@@ -83,6 +91,10 @@ void TinyGLRenderer::clear(const Math::Vector4d &clearColor) {
 	tglClear(TGL_COLOR_BUFFER_BIT | TGL_DEPTH_BUFFER_BIT);
 }
 
+void TinyGLRenderer::setupViewport(int x, int y, int width, int height) {
+	tglViewport(x, y, width, height);
+}
+
 void TinyGLRenderer::drawFace(uint face) {
 	tglBegin(TGL_TRIANGLE_STRIP);
 	for (uint i = 0; i < 4; i++) {
@@ -94,9 +106,6 @@ void TinyGLRenderer::drawFace(uint face) {
 }
 
 void TinyGLRenderer::drawCube(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());
 
@@ -114,9 +123,6 @@ 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());
 
@@ -150,9 +156,6 @@ void TinyGLRenderer::flipBuffer() {
 }
 
 void TinyGLRenderer::dimRegionInOut(float fade) {
-	Common::Rect vp = viewport();
-	tglViewport(vp.left, _system->getHeight() - vp.top - vp.height(), vp.width(), vp.height());
-
 	tglMatrixMode(TGL_PROJECTION);
 	tglPushMatrix();
 	tglLoadIdentity();
@@ -167,7 +170,6 @@ void TinyGLRenderer::dimRegionInOut(float fade) {
 	tglDepthMask(TGL_FALSE);
 
 	tglColor4f(0.0f, 0.0f, 0.0f, 1.0f - fade);
-
 	tglEnableClientState(TGL_VERTEX_ARRAY);
 	tglVertexPointer(2, TGL_FLOAT, 0, dimRegionVertices);
 	tglDrawElements(TGL_TRIANGLE_STRIP, 4, TGL_UNSIGNED_INT, dimRegionIndices);
@@ -181,4 +183,57 @@ void TinyGLRenderer::dimRegionInOut(float fade) {
 	tglPopMatrix();
 }
 
+void TinyGLRenderer::drawInViewport() {
+	static TGLfloat box2Vertices[] = {
+		//  X      Y
+		-0.1f,  0.1f,
+		 0.1f,  0.1f,
+		-0.1f, -0.1f,
+		 0.1f, -0.1f,
+	};
+	tglMatrixMode(TGL_PROJECTION);
+	tglPushMatrix();
+	tglLoadIdentity();
+
+	tglMatrixMode(TGL_MODELVIEW);
+	tglPushMatrix();
+	tglLoadIdentity();
+
+	tglEnable(TGL_BLEND);
+	tglBlendFunc(TGL_ONE, TGL_ONE_MINUS_SRC_ALPHA);
+	tglDisable(TGL_DEPTH_TEST);
+	tglDepthMask(TGL_FALSE);
+
+	tglColor4f(0.0f, 1.0f, 0.0f, 1.0f);
+	tglEnableClientState(TGL_VERTEX_ARRAY);
+	tglVertexPointer(2, TGL_FLOAT, 2 * sizeof(TGLfloat), &boxVertices[0]);
+	tglDrawArrays(TGL_TRIANGLE_STRIP, 0, 4);
+	tglDisableClientState(TGL_VERTEX_ARRAY);
+
+	tglPushMatrix();
+	_pos.x() += 0.01;
+	_pos.y() += 0.01;
+	if (_pos.x() >= 1.0f) {
+		_pos.x() = -1.0;
+		_pos.y() = -1.0;
+	}
+	tglTranslatef(_pos.x(), _pos.y(), 0);
+
+	tglPolygonOffset(-1.0f, 0.0f);
+	tglEnable(TGL_POLYGON_OFFSET_FILL);
+	tglColor4f(1.0f, 0.0f, 0.0f, 1.0f);
+	tglEnableClientState(TGL_VERTEX_ARRAY);
+	tglVertexPointer(2, TGL_FLOAT, 2 * sizeof(TGLfloat), &box2Vertices[0]);
+	tglDrawArrays(TGL_TRIANGLE_STRIP, 0, 4);
+	tglDisableClientState(TGL_VERTEX_ARRAY);
+	tglDisable(TGL_POLYGON_OFFSET_FILL);
+
+	tglMatrixMode(TGL_MODELVIEW);
+	tglPopMatrix();
+	tglPopMatrix();
+
+	tglMatrixMode(TGL_PROJECTION);
+	tglPopMatrix();
+}
+
 } // End of namespace Playground3d
diff --git a/engines/playground3d/gfx_tinygl.h b/engines/playground3d/gfx_tinygl.h
index 03ae1561ff..3d0abeead7 100644
--- a/engines/playground3d/gfx_tinygl.h
+++ b/engines/playground3d/gfx_tinygl.h
@@ -43,16 +43,19 @@ public:
 
 	virtual void clear(const Math::Vector4d &clearColor) override;
 
+	virtual void setupViewport(int x, int y, int width, int height) 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 dimRegionInOut(float fade) override;
+	virtual void drawInViewport() override;
 
 	virtual void flipBuffer() override;
 
 private:
-	void drawFace(uint face);
-
 	TinyGL::FrameBuffer *_fb;
+	Math::Vector3d _pos;
+
+	void drawFace(uint face);
 };
 
 } // End of namespace Playground3d
diff --git a/engines/playground3d/playground3d.cpp b/engines/playground3d/playground3d.cpp
index 64e77f9abe..b807a13495 100644
--- a/engines/playground3d/playground3d.cpp
+++ b/engines/playground3d/playground3d.cpp
@@ -66,6 +66,7 @@ Common::Error Playground3dEngine::run() {
 	// 1 - rotated colorfull cube
 	// 2 - rotated two triangles with depth offset
 	// 3 - fade in/out
+	// 4 - moving filled rectangle in viewport
 	int testId = 1;
 
 	switch (testId) {
@@ -79,6 +80,9 @@ Common::Error Playground3dEngine::run() {
 		case 3:
 			_clearColor = Math::Vector4d(1.0f, 0.0f, 0.0f, 1.0f);
 			break;
+		case 4:
+			_clearColor = Math::Vector4d(0.5f, 0.5f, 0.5f, 1.0f);
+			break;
 		default:
 			assert(false);
 	}
@@ -140,6 +144,10 @@ void Playground3dEngine::dimRegionInOut() {
 	}
 }
 
+void Playground3dEngine::drawInViewport() {
+	_gfx->drawInViewport();
+}
+
 void Playground3dEngine::drawFrame(int testId) {
 	_gfx->clear(_clearColor);
 
@@ -148,6 +156,9 @@ void Playground3dEngine::drawFrame(int testId) {
 	float fov = 45.0f;
 	_gfx->setupCameraPerspective(pitch, heading, fov);
 
+	Common::Rect vp = _gfx->viewport();
+	_gfx->setupViewport(vp.left, _system->getHeight() - vp.top - vp.height(), vp.width(), vp.height());
+
 	switch (testId) {
 		case 1:
 			drawAndRotateCube();
@@ -158,6 +169,10 @@ void Playground3dEngine::drawFrame(int testId) {
 		case 3:
 			dimRegionInOut();
 			break;
+		case 4:
+			_gfx->setupViewport(vp.left + 40, _system->getHeight() - vp.top - vp.height() + 40, vp.width() - 80, vp.height() - 80);
+			drawInViewport();
+			break;
 		default:
 			assert(false);
 	}
diff --git a/engines/playground3d/playground3d.h b/engines/playground3d/playground3d.h
index 4b55ad7a6a..12af51b5fb 100644
--- a/engines/playground3d/playground3d.h
+++ b/engines/playground3d/playground3d.h
@@ -59,6 +59,7 @@ private:
 	void drawAndRotateCube();
 	void drawPolyOffsetTest();
 	void dimRegionInOut();
+	void drawInViewport();
 };
 
 } // End of namespace Playground3d




More information about the Scummvm-git-logs mailing list