diff --git a/engines/hpl1/metaengine.cpp b/engines/hpl1/metaengine.cpp index fa9f69fc780..6e529acc96c 100644 --- a/engines/hpl1/metaengine.cpp +++ b/engines/hpl1/metaengine.cpp @@ -25,6 +25,9 @@ #include "common/translation.h" #include "hpl1/detection.h" #include "hpl1/hpl1.h" +#include "hpl1/opengl.h" +#include "graphics/scaler.h" +#include "graphics/thumbnail.h" #include "common/savefile.h" #include "common/system.h" @@ -47,6 +50,15 @@ bool Hpl1MetaEngine::hasFeature(MetaEngineFeature f) const { (f == kSupportsLoadingDuringStartup); } +void Hpl1MetaEngine::getSavegameThumbnail(Graphics::Surface &thumbnail) { + Common::ScopedPtr screen = Hpl1::createViewportScreenshot(); + Common::ScopedPtr scaledScreen(screen->scale( kThumbnailWidth, kThumbnailHeight2)); + scaledScreen->convertToInPlace(Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0)); + thumbnail.copyFrom(*scaledScreen); + screen->free(); + scaledScreen->free(); +} + static Common::U32String formatSave(const Common::String &filename) { const int begin = filename.findFirstOf('.') + 1; const int len = filename.findLastOf('_') - begin; diff --git a/engines/hpl1/metaengine.h b/engines/hpl1/metaengine.h index bb16de0d636..39fe205a3c6 100644 --- a/engines/hpl1/metaengine.h +++ b/engines/hpl1/metaengine.h @@ -39,6 +39,8 @@ public: SaveStateList listSaves(const char *target) const override; + void getSavegameThumbnail(Graphics::Surface &thumbnail) override; + Common::Array initKeymaps(const char *target) const override; }; diff --git a/engines/hpl1/opengl.cpp b/engines/hpl1/opengl.cpp index 6d5ab49fe25..151fc9bf01a 100644 --- a/engines/hpl1/opengl.cpp +++ b/engines/hpl1/opengl.cpp @@ -21,6 +21,9 @@ #include "hpl1/opengl.h" #include "hpl1/debug.h" +#include "common/rect.h" +#include "graphics/surface.h" +#include "common/system.h" namespace Hpl1 { @@ -42,4 +45,28 @@ void checkOGLErrors(const char *function, const int line) { logError(kDebugOpenGL, "Opengl error: \'%s\' in function %s - %d\n", getErrorString(code), function, line); } + +static Common::Rect getGLViewport() { + int viewportSize[4]; + GL_CHECK(glGetIntegerv(GL_VIEWPORT, viewportSize)); + return Common::Rect(viewportSize[0], viewportSize[1], viewportSize[2], viewportSize[3]); +} + +static Graphics::PixelFormat getRGBAPixelFormat() { +#ifdef SCUMM_BIG_ENDIAN + return Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0); +#else + return Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24); +#endif +} + +Common::ScopedPtr createViewportScreenshot() { + Common::ScopedPtr screen(new Graphics::Surface()); + Common::Rect viewportSize = getGLViewport(); + screen->create(viewportSize.width(), viewportSize.height(), getRGBAPixelFormat()); + GL_CHECK(glReadPixels(viewportSize.left, g_system->getHeight() - viewportSize.bottom, viewportSize.width(), viewportSize.height(), GL_RGBA, GL_UNSIGNED_BYTE, screen->getPixels())); + screen->flipVertical(Common::Rect(screen->w, screen->h)); + return screen; +} + } // End of namespace Hpl1 \ No newline at end of file diff --git a/engines/hpl1/opengl.h b/engines/hpl1/opengl.h index d2fe5075819..0f65156d153 100644 --- a/engines/hpl1/opengl.h +++ b/engines/hpl1/opengl.h @@ -26,11 +26,20 @@ #define USE_GLAD #include "graphics/opengl/system_headers.h" #include "graphics/opengl/context.h" +#include "common/ptr.h" + +namespace Graphics { + +class Surface; + +} namespace Hpl1 { void checkOGLErrors(const char *function, int line); +Common::ScopedPtr createViewportScreenshot(); + } #define GL_CHECK(x) {x; ::Hpl1::checkOGLErrors(__func__, __LINE__);}