[Scummvm-git-logs] scummvm master -> 1c1125d8ac082b59381ead1980713a4f122e3644
lephilousophe
noreply at scummvm.org
Sat Aug 31 14:29:25 UTC 2024
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:
1c1125d8ac GRIM: Refresh screen on a regular basis when possible
Commit: 1c1125d8ac082b59381ead1980713a4f122e3644
https://github.com/scummvm/scummvm/commit/1c1125d8ac082b59381ead1980713a4f122e3644
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2024-08-31T16:29:21+02:00
Commit Message:
GRIM: Refresh screen on a regular basis when possible
The only case where it's not possible is when we directly draw on OpenGL
backbuffer.
In TinyGL, we only update the backend screen without doing any
rendering.
Changed paths:
engines/grim/gfx_base.h
engines/grim/gfx_opengl.cpp
engines/grim/gfx_opengl.h
engines/grim/gfx_opengl_shaders.cpp
engines/grim/gfx_opengl_shaders.h
engines/grim/gfx_tinygl.cpp
engines/grim/gfx_tinygl.h
engines/grim/grim.cpp
diff --git a/engines/grim/gfx_base.h b/engines/grim/gfx_base.h
index d8c2cd2c4bd..aab552314f7 100644
--- a/engines/grim/gfx_base.h
+++ b/engines/grim/gfx_base.h
@@ -109,8 +109,10 @@ public:
/**
* Swap the buffers, making the drawn screen visible
+ *
+ * @param opportunistic True when the flip can be avoided to spare CPU
*/
- virtual void flipBuffer() = 0;
+ virtual void flipBuffer(bool opportunistic = false) = 0;
/**
* FIXME: The implementations of these functions (for Grim and EMI, respectively)
diff --git a/engines/grim/gfx_opengl.cpp b/engines/grim/gfx_opengl.cpp
index 42f23abbe67..4950976f917 100644
--- a/engines/grim/gfx_opengl.cpp
+++ b/engines/grim/gfx_opengl.cpp
@@ -259,7 +259,18 @@ void GfxOpenGL::clearDepthBuffer() {
glClear(GL_DEPTH_BUFFER_BIT);
}
-void GfxOpenGL::flipBuffer() {
+void GfxOpenGL::flipBuffer(bool opportunistic) {
+ if (opportunistic) {
+ GLint fbo = 0;
+ glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &fbo);
+ if (fbo == 0) {
+ // Don't flip if we are not rendering on FBO
+ // Flipping without any draw is undefined
+ // When using an FBO, the older texture will be used
+ return;
+ }
+ }
+
g_system->updateScreen();
}
diff --git a/engines/grim/gfx_opengl.h b/engines/grim/gfx_opengl.h
index bfea65cf2ca..5ec9d3e017a 100644
--- a/engines/grim/gfx_opengl.h
+++ b/engines/grim/gfx_opengl.h
@@ -52,7 +52,7 @@ public:
void clearScreen() override;
void clearDepthBuffer() override;
- void flipBuffer() override;
+ void flipBuffer(bool opportunistic = false) override;
bool isHardwareAccelerated() override;
bool supportsShaders() override;
diff --git a/engines/grim/gfx_opengl_shaders.cpp b/engines/grim/gfx_opengl_shaders.cpp
index b34cbdd6275..27ef39c0131 100644
--- a/engines/grim/gfx_opengl_shaders.cpp
+++ b/engines/grim/gfx_opengl_shaders.cpp
@@ -514,7 +514,18 @@ void GfxOpenGLS::clearDepthBuffer() {
glClear(GL_DEPTH_BUFFER_BIT);
}
-void GfxOpenGLS::flipBuffer() {
+void GfxOpenGLS::flipBuffer(bool opportunistic) {
+ if (opportunistic) {
+ GLint fbo = 0;
+ glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &fbo);
+ if (fbo == 0) {
+ // Don't flip if we are not rendering on FBO
+ // Flipping without any draw is undefined
+ // When using an FBO, the older texture will be used
+ return;
+ }
+ }
+
g_system->updateScreen();
}
diff --git a/engines/grim/gfx_opengl_shaders.h b/engines/grim/gfx_opengl_shaders.h
index 7034788ef83..086235c4337 100644
--- a/engines/grim/gfx_opengl_shaders.h
+++ b/engines/grim/gfx_opengl_shaders.h
@@ -65,7 +65,7 @@ public:
/**
* Swap the buffers, making the drawn screen visible
*/
- void flipBuffer() override;
+ void flipBuffer(bool opportunistic = false) override;
void getScreenBoundingBox(const Mesh *mesh, int *x1, int *y1, int *x2, int *y2) override;
void getScreenBoundingBox(const EMIModel *model, int *x1, int *y1, int *x2, int *y2) override;
diff --git a/engines/grim/gfx_tinygl.cpp b/engines/grim/gfx_tinygl.cpp
index ef563fcf096..4c828f6e463 100644
--- a/engines/grim/gfx_tinygl.cpp
+++ b/engines/grim/gfx_tinygl.cpp
@@ -175,7 +175,12 @@ void GfxTinyGL::clearDepthBuffer() {
tglClear(TGL_DEPTH_BUFFER_BIT);
}
-void GfxTinyGL::flipBuffer() {
+void GfxTinyGL::flipBuffer(bool opportunistic) {
+ if (opportunistic) {
+ g_system->updateScreen();
+ return;
+ }
+
Common::List<Common::Rect> dirtyAreas;
TinyGL::presentBuffer(dirtyAreas);
diff --git a/engines/grim/gfx_tinygl.h b/engines/grim/gfx_tinygl.h
index c9091b69dec..65ce4d4a2ec 100644
--- a/engines/grim/gfx_tinygl.h
+++ b/engines/grim/gfx_tinygl.h
@@ -54,7 +54,7 @@ public:
void clearScreen() override;
void clearDepthBuffer() override;
- void flipBuffer() override;
+ void flipBuffer(bool opportunistic = false) override;
bool isHardwareAccelerated() override;
bool supportsShaders() override;
diff --git a/engines/grim/grim.cpp b/engines/grim/grim.cpp
index 43ddb7f7eac..88e78d23c0f 100644
--- a/engines/grim/grim.cpp
+++ b/engines/grim/grim.cpp
@@ -653,9 +653,7 @@ void GrimEngine::playAspyrLogo() {
uint32 startTime = g_system->getMillis();
updateDisplayScene();
- if (_doFlip) {
- doFlip();
- }
+ doFlip();
// Process events to allow the user to skip the logo.
Common::Event event;
while (g_system->getEventManager()->pollEvent(event)) {
@@ -957,7 +955,11 @@ void GrimEngine::drawNormalMode() {
void GrimEngine::doFlip() {
_frameCounter++;
- if (!_doFlip) {
+ // When possible, flip the buffer
+ // This makes sure the screen is refreshed on a regular basis
+ // The image is properly resized if needed and backend overlays are displayed
+ if (!_doFlip || (_mode == PauseMode)) {
+ g_driver->flipBuffer(true);
return;
}
@@ -1131,9 +1133,7 @@ void GrimEngine::mainLoop() {
updateDisplayScene();
}
- if (_mode != PauseMode) {
- doFlip();
- }
+ doFlip();
// We do not want the scripts to update while a movie is playing in the PS2-version.
if (!(getGamePlatform() == Common::kPlatformPS2 && _mode == SmushMode)) {
More information about the Scummvm-git-logs
mailing list