diff --git a/dists/scummvm.rc b/dists/scummvm.rc index 56cff34f63c..a5206a2f36e 100644 --- a/dists/scummvm.rc +++ b/dists/scummvm.rc @@ -167,10 +167,10 @@ shaders/stark_shadow.vertex FILE "engines/stark/shaders/stark_shadow #if PLUGIN_ENABLED_STATIC(WINTERMUTE) shaders/wme_fade.fragment FILE "engines/wintermute/base/gfx/opengl/shaders/wme_fade.fragment" shaders/wme_fade.vertex FILE "engines/wintermute/base/gfx/opengl/shaders/wme_fade.vertex" -shaders/wme_flat_shadow_mask.fragment FILE "engines/wintermute/base/gfx/opengl/shaders/wme_flat_shadow_mask.fragment" -shaders/wme_flat_shadow_mask.vertex FILE "engines/wintermute/base/gfx/opengl/shaders/wme_flat_shadow_mask.vertex" -shaders/wme_flat_shadow_modelx.fragment FILE "engines/wintermute/base/gfx/opengl/shaders/wme_flat_shadow_modelx.fragment" -shaders/wme_flat_shadow_modelx.vertex FILE "engines/wintermute/base/gfx/opengl/shaders/wme_flat_shadow_modelx.vertex" +shaders/wme_flat_shadow_mask.fragment FILE "engines/wintermute/base/gfx/opengl/shaders/wme_flat_shadow_mask.fragment" +shaders/wme_flat_shadow_mask.vertex FILE "engines/wintermute/base/gfx/opengl/shaders/wme_flat_shadow_mask.vertex" +shaders/wme_flat_shadow_modelx.fragment FILE "engines/wintermute/base/gfx/opengl/shaders/wme_flat_shadow_modelx.fragment" +shaders/wme_flat_shadow_modelx.vertex FILE "engines/wintermute/base/gfx/opengl/shaders/wme_flat_shadow_modelx.vertex" shaders/wme_geometry.fragment FILE "engines/wintermute/base/gfx/opengl/shaders/wme_geometry.fragment" shaders/wme_geometry.vertex FILE "engines/wintermute/base/gfx/opengl/shaders/wme_geometry.vertex" shaders/wme_line.fragment FILE "engines/wintermute/base/gfx/opengl/shaders/wme_line.fragment" @@ -187,6 +187,8 @@ shaders/wme_sprite.vertex FILE "engines/wintermute/base/gfx/ope #if PLUGIN_ENABLED_STATIC(PLAYGROUND3D) shaders/playground3d_cube.fragment FILE "engines/playground3d/shaders/playground3d_cube.fragment" shaders/playground3d_cube.vertex FILE "engines/playground3d/shaders/playground3d_cube.vertex" +shaders/playground3d_fade.fragment FILE "engines/playground3d/shaders/playground3d_fade.fragment" +shaders/playground3d_fade.vertex FILE "engines/playground3d/shaders/playground3d_fade.vertex" #endif #endif #endif diff --git a/engines/playground3d/gfx.h b/engines/playground3d/gfx.h index 836e4153472..a6ced749abc 100644 --- a/engines/playground3d/gfx.h +++ b/engines/playground3d/gfx.h @@ -38,7 +38,7 @@ public: virtual ~Renderer(); virtual void init() = 0; - virtual void clear() = 0; + virtual void clear(const Math::Vector4d &clearColor) = 0; /** * Swap the buffers, making the drawn screen visible @@ -56,6 +56,7 @@ public: 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; protected: OSystem *_system; diff --git a/engines/playground3d/gfx_opengl.cpp b/engines/playground3d/gfx_opengl.cpp index 1532c34718a..e7044bb2b30 100644 --- a/engines/playground3d/gfx_opengl.cpp +++ b/engines/playground3d/gfx_opengl.cpp @@ -33,6 +33,14 @@ namespace Playground3d { +static const GLfloat dimRegionVertices[] = { + // X Y + -0.5f, 0.5f, + 0.5f, 0.5f, + -0.5f, -0.5f, + 0.5f, -0.5f, +}; + Renderer *CreateGfxOpenGL(OSystem *system) { return new OpenGLRenderer(system); } @@ -60,12 +68,13 @@ void OpenGLRenderer::init() { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); + glDisable(GL_TEXTURE_2D); glDisable(GL_LIGHTING); glEnable(GL_DEPTH_TEST); } -void OpenGLRenderer::clear() { - glClearColor(0.5f, 0.5f, 0.5f, 1.0f); +void OpenGLRenderer::clear(const Math::Vector4d &clearColor) { + glClearColor(clearColor.x(), clearColor.y(), clearColor.z(), clearColor.w()); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } @@ -130,6 +139,36 @@ void OpenGLRenderer::drawPolyOffsetTest(const Math::Vector3d &pos, const Math::V glDisable(GL_POLYGON_OFFSET_FILL); } +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(); + + 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, 0.0f, 0.0f, 1.0f - fade); + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), &dimRegionVertices[0]); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + glDisableClientState(GL_VERTEX_ARRAY); + + glMatrixMode(GL_MODELVIEW); + 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 b2dc406c397..f8a9fd6d607 100644 --- a/engines/playground3d/gfx_opengl.h +++ b/engines/playground3d/gfx_opengl.h @@ -41,10 +41,11 @@ public: virtual void init() override; - virtual void clear() override; + virtual void clear(const Math::Vector4d &clearColor) 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; private: void drawFace(uint face); diff --git a/engines/playground3d/gfx_opengl_shaders.cpp b/engines/playground3d/gfx_opengl_shaders.cpp index 20cf8133975..bdea48e9a55 100644 --- a/engines/playground3d/gfx_opengl_shaders.cpp +++ b/engines/playground3d/gfx_opengl_shaders.cpp @@ -39,6 +39,14 @@ namespace Playground3d { +static const GLfloat dimRegionVertices[] = { + // X Y + -0.5f, 0.5f, + 0.5f, 0.5f, + -0.5f, -0.5f, + 0.5f, -0.5f, +}; + Renderer *CreateGfxOpenGLShader(OSystem *system) { return new ShaderRenderer(system); } @@ -47,13 +55,17 @@ ShaderRenderer::ShaderRenderer(OSystem *system) : Renderer(system), _currentViewport(kOriginalWidth, kOriginalHeight), _cubeShader(nullptr), - _cubeVBO(0) { + _fadeShader(nullptr), + _cubeVBO(0), + _fadeVBO(0) { } ShaderRenderer::~ShaderRenderer() { OpenGL::ShaderGL::freeBuffer(_cubeVBO); + OpenGL::ShaderGL::freeBuffer(_fadeVBO); delete _cubeShader; + delete _fadeShader; } void ShaderRenderer::init() { @@ -63,17 +75,22 @@ void ShaderRenderer::init() { glEnable(GL_DEPTH_TEST); - static const char* attributes[] = { "position", "normal", "color", "texcoord", NULL }; - _cubeShader = OpenGL::ShaderGL::fromFiles("playground3d_cube", attributes); + static const char *cubeAttributes[] = { "position", "normal", "color", "texcoord", NULL }; + _cubeShader = OpenGL::ShaderGL::fromFiles("playground3d_cube", cubeAttributes); _cubeVBO = OpenGL::ShaderGL::createBuffer(GL_ARRAY_BUFFER, sizeof(cubeVertices), cubeVertices); _cubeShader->enableVertexAttribute("texcoord", _cubeVBO, 2, GL_FLOAT, GL_FALSE, 11 * sizeof(float), 0); _cubeShader->enableVertexAttribute("position", _cubeVBO, 3, GL_FLOAT, GL_FALSE, 11 * sizeof(float), 8); _cubeShader->enableVertexAttribute("normal", _cubeVBO, 3, GL_FLOAT, GL_FALSE, 11 * sizeof(float), 20); _cubeShader->enableVertexAttribute("color", _cubeVBO, 3, GL_FLOAT, GL_FALSE, 11 * sizeof(float), 32); + + static const char* fadeAttributes[] = { "position", nullptr }; + _fadeShader = OpenGL::ShaderGL::fromFiles("playground3d_fade", fadeAttributes); + _fadeVBO = OpenGL::ShaderGL::createBuffer(GL_ARRAY_BUFFER, sizeof(dimRegionVertices), dimRegionVertices); + _fadeShader->enableVertexAttribute("position", _fadeVBO, 2, GL_FLOAT, GL_TRUE, 2 * sizeof(float), 0); } -void ShaderRenderer::clear() { - glClearColor(0.5f, 0.5f, 0.5f, 1.0f); +void ShaderRenderer::clear(const Math::Vector4d &clearColor) { + glClearColor(clearColor.x(), clearColor.y(), clearColor.z(), clearColor.w()); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } @@ -100,6 +117,21 @@ void ShaderRenderer::drawPolyOffsetTest(const Math::Vector3d &pos, const Math::V error("Polygon offset test not implemented yet"); } +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); + glDepthMask(GL_FALSE); + + _fadeShader->use(); + _fadeShader->setUniform1f("alphaLevel", 1.0 - fade); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + _fadeShader->unbind(); +} + } // End of namespace Playground3d #endif diff --git a/engines/playground3d/gfx_opengl_shaders.h b/engines/playground3d/gfx_opengl_shaders.h index 9ad655d0ec4..ff6dd2ab470 100644 --- a/engines/playground3d/gfx_opengl_shaders.h +++ b/engines/playground3d/gfx_opengl_shaders.h @@ -41,15 +41,18 @@ public: virtual void init() override; - virtual void clear() override; + virtual void clear(const Math::Vector4d &clearColor) 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; private: OpenGL::ShaderGL *_cubeShader; + OpenGL::ShaderGL *_fadeShader; GLuint _cubeVBO; + GLuint _fadeVBO; Common::Rect _currentViewport; }; diff --git a/engines/playground3d/gfx_tinygl.cpp b/engines/playground3d/gfx_tinygl.cpp index dfc4960a014..a4ed0ec92a8 100644 --- a/engines/playground3d/gfx_tinygl.cpp +++ b/engines/playground3d/gfx_tinygl.cpp @@ -35,6 +35,18 @@ namespace Playground3d { +static const TGLfloat dimRegionVertices[] = { + // X Y + -0.5f, 0.5f, + 0.5f, 0.5f, + -0.5f, -0.5f, + 0.5f, -0.5f, +}; + +static const TGLuint dimRegionIndices[] = { + 0, 1, 2, 3 +}; + Renderer *CreateGfxTinyGL(OSystem *system) { return new TinyGLRenderer(system); } @@ -66,8 +78,8 @@ void TinyGLRenderer::init() { tglEnable(TGL_DEPTH_TEST); } -void TinyGLRenderer::clear() { - tglClearColor(0.5f, 0.5f, 0.5f, 1.0f); +void TinyGLRenderer::clear(const Math::Vector4d &clearColor) { + tglClearColor(clearColor.x(), clearColor.y(), clearColor.z(), clearColor.w()); tglClear(TGL_COLOR_BUFFER_BIT | TGL_DEPTH_BUFFER_BIT); } @@ -137,4 +149,36 @@ void TinyGLRenderer::flipBuffer() { g_system->copyRectToScreen(_fb->getPixelBuffer(), _fb->linesize, 0, 0, _fb->xsize, _fb->ysize); } +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(); + + 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, 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); + //tglDrawArrays(TGL_TRIANGLE_STRIP, 0, 4); + tglDisableClientState(TGL_VERTEX_ARRAY); + + tglMatrixMode(TGL_MODELVIEW); + tglPopMatrix(); + + tglMatrixMode(TGL_PROJECTION); + tglPopMatrix(); +} + } // End of namespace Playground3d diff --git a/engines/playground3d/gfx_tinygl.h b/engines/playground3d/gfx_tinygl.h index 0b435192ee3..03ae1561ffb 100644 --- a/engines/playground3d/gfx_tinygl.h +++ b/engines/playground3d/gfx_tinygl.h @@ -41,10 +41,11 @@ public: virtual void init() override; - virtual void clear() override; + virtual void clear(const Math::Vector4d &clearColor) 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 flipBuffer() override; diff --git a/engines/playground3d/playground3d.cpp b/engines/playground3d/playground3d.cpp index 68184553bf2..79d5ed3d020 100644 --- a/engines/playground3d/playground3d.cpp +++ b/engines/playground3d/playground3d.cpp @@ -46,7 +46,8 @@ bool Playground3dEngine::hasFeature(EngineFeature f) const { Playground3dEngine::Playground3dEngine(OSystem *syst) : Engine(syst), _system(syst), _frameLimiter(0), - _rotateAngleX(0), _rotateAngleY(0), _rotateAngleZ(0) { + _rotateAngleX(0), _rotateAngleY(0), _rotateAngleZ(0), + _clearColor(0.0f, 0.0f, 0.0f, 1.0f), _fade(1.0f), _fadeIn(false) { } Playground3dEngine::~Playground3dEngine() { @@ -57,21 +58,25 @@ Playground3dEngine::~Playground3dEngine() { Common::Error Playground3dEngine::run() { _gfx = createRenderer(_system); _gfx->init(); - _gfx->clear(); _frameLimiter = new Gfx::FrameLimiter(_system, ConfMan.getInt("engine_speed")); _system->showMouse(true); // 1 - rotated colorfull cube - // 2 - rotated two traingles with depth offset + // 2 - rotated two triangles with depth offset + // 3 - fade in/out int testId = 1; switch (testId) { case 1: + _clearColor = Math::Vector4d(0.5f, 0.5f, 0.5f, 1.0f); _rotateAngleX = 45, _rotateAngleY = 45, _rotateAngleZ = 10; break; case 2: + _clearColor = Math::Vector4d(0.5f, 0.5f, 0.5f, 1.0f); + case 3: + _clearColor = Math::Vector4d(1.0f, 0.0f, 0.0f, 1.0f); break; default: assert(false); @@ -119,8 +124,23 @@ void Playground3dEngine::drawPolyOffsetTest() { _rotateAngleY = 0; } +void Playground3dEngine::dimRegionInOut() { + _gfx->dimRegionInOut(_fade); + if (_fadeIn) + _fade += 0.01f; + else + _fade -= 0.01f; + if (_fade > 1.0f) { + _fade = 1; + _fadeIn = false; + } else if (_fade < 0.0f) { + _fade = 0; + _fadeIn = true; + } +} + void Playground3dEngine::drawFrame(int testId) { - _gfx->clear(); + _gfx->clear(_clearColor); float pitch = 0.0f; float heading = 0.0f; @@ -134,6 +154,9 @@ void Playground3dEngine::drawFrame(int testId) { case 2: drawPolyOffsetTest(); break; + case 3: + dimRegionInOut(); + break; default: assert(false); } diff --git a/engines/playground3d/playground3d.h b/engines/playground3d/playground3d.h index 8a23f5a9616..b571f533216 100644 --- a/engines/playground3d/playground3d.h +++ b/engines/playground3d/playground3d.h @@ -49,11 +49,15 @@ private: OSystem *_system; Renderer *_gfx; Gfx::FrameLimiter *_frameLimiter; + Math::Vector4d _clearColor; + float _fade; + bool _fadeIn; float _rotateAngleX, _rotateAngleY, _rotateAngleZ; void drawAndRotateCube(); void drawPolyOffsetTest(); + void dimRegionInOut(); }; } // End of namespace Playground3d diff --git a/engines/playground3d/shaders/playground3d_cube.fragment b/engines/playground3d/shaders/playground3d_cube.fragment index 433e5d0eb5f..d6917e6b253 100644 --- a/engines/playground3d/shaders/playground3d_cube.fragment +++ b/engines/playground3d/shaders/playground3d_cube.fragment @@ -6,8 +6,7 @@ OUTPUT uniform bool textured; uniform sampler2D tex; -void main() -{ +void main() { outColor = vec4(Color, 1.0); if (textured) { outColor *= texture(tex, Texcoord); diff --git a/engines/playground3d/shaders/playground3d_cube.vertex b/engines/playground3d/shaders/playground3d_cube.vertex index 62861010321..05f4126c82f 100644 --- a/engines/playground3d/shaders/playground3d_cube.vertex +++ b/engines/playground3d/shaders/playground3d_cube.vertex @@ -13,8 +13,7 @@ uniform vec3 modelPos; out vec2 Texcoord; out vec3 Color; -void main() -{ +void main() { Texcoord = texcoord; vec4 pos = rotateMatrix * vec4(position, 1.0); diff --git a/engines/playground3d/shaders/playground3d_fade.fragment b/engines/playground3d/shaders/playground3d_fade.fragment new file mode 100644 index 00000000000..069bdba5cff --- /dev/null +++ b/engines/playground3d/shaders/playground3d_fade.fragment @@ -0,0 +1,8 @@ + +OUTPUT + +uniform float alphaLevel; + +void main() { + outColor = vec4(0.0, 0.0, 0.0, alphaLevel); +} diff --git a/engines/playground3d/shaders/playground3d_fade.vertex b/engines/playground3d/shaders/playground3d_fade.vertex new file mode 100644 index 00000000000..92f62ba08ee --- /dev/null +++ b/engines/playground3d/shaders/playground3d_fade.vertex @@ -0,0 +1,5 @@ +in vec2 position; + +void main() { + gl_Position = vec4(position, 0.0, 1.0); +}