From b828199c2596805fa29631d10fb6a507331112e4 Mon Sep 17 00:00:00 2001 From: Walter Agazzi Date: Wed, 1 Mar 2023 21:07:59 +0100 Subject: [PATCH] AGS: Engine: renderers support creating DDB as a render target Partially from upstream 4c8218e9ca4da7403ff14e45c57584517d2abc2f --- engines/ags/engine/gfx/ali_3d_scummvm.cpp | 4 ++++ engines/ags/engine/gfx/ali_3d_scummvm.h | 1 + engines/ags/engine/gfx/gfx_driver_base.h | 4 +++- engines/ags/engine/gfx/graphics_driver.h | 8 +++++++- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/engines/ags/engine/gfx/ali_3d_scummvm.cpp b/engines/ags/engine/gfx/ali_3d_scummvm.cpp index 8686d75e117..3cea00c5301 100644 --- a/engines/ags/engine/gfx/ali_3d_scummvm.cpp +++ b/engines/ags/engine/gfx/ali_3d_scummvm.cpp @@ -251,6 +251,10 @@ IDriverDependantBitmap *ScummVMRendererGraphicsDriver::CreateDDBFromBitmap(Bitma return new ALSoftwareBitmap(bitmap, opaque, hasAlpha); } +IDriverDependantBitmap *ScummVMRendererGraphicsDriver::CreateRenderTargetDDB(int width, int height, int color_depth, bool opaque) { + return new ALSoftwareBitmap(width, height, color_depth, opaque); +} + void ScummVMRendererGraphicsDriver::UpdateDDBFromBitmap(IDriverDependantBitmap *bitmapToUpdate, Bitmap *bitmap, bool hasAlpha) { ALSoftwareBitmap *alSwBmp = (ALSoftwareBitmap *)bitmapToUpdate; alSwBmp->_bmp = bitmap; diff --git a/engines/ags/engine/gfx/ali_3d_scummvm.h b/engines/ags/engine/gfx/ali_3d_scummvm.h index 768a91fcfe2..526356077a8 100644 --- a/engines/ags/engine/gfx/ali_3d_scummvm.h +++ b/engines/ags/engine/gfx/ali_3d_scummvm.h @@ -176,6 +176,7 @@ public: int GetCompatibleBitmapFormat(int color_depth) override; IDriverDependantBitmap *CreateDDB(int width, int height, int color_depth, bool opaque) override; IDriverDependantBitmap *CreateDDBFromBitmap(Bitmap *bitmap, bool hasAlpha, bool opaque) override; + IDriverDependantBitmap *CreateRenderTargetDDB(int width, int height, int color_depth, bool opaque) override; void UpdateDDBFromBitmap(IDriverDependantBitmap *ddb, Bitmap *bitmap, bool hasAlpha) override; void DestroyDDB(IDriverDependantBitmap *ddb) override; diff --git a/engines/ags/engine/gfx/gfx_driver_base.h b/engines/ags/engine/gfx/gfx_driver_base.h index ba8aaa25602..3e59a8d00ea 100644 --- a/engines/ags/engine/gfx/gfx_driver_base.h +++ b/engines/ags/engine/gfx/gfx_driver_base.h @@ -223,7 +223,9 @@ public: void SetMemoryBackBuffer(Bitmap *backBuffer) override; Bitmap *GetStageBackBuffer(bool mark_dirty) override; bool GetStageMatrixes(RenderMatrixes &rm) override; + // Creates new texture using given parameters IDriverDependantBitmap *CreateDDB(int width, int height, int color_depth, bool opaque) override = 0; + // Creates new texture and copy bitmap contents over IDriverDependantBitmap *CreateDDBFromBitmap(Bitmap *bitmap, bool hasAlpha, bool opaque = false) override; // Get shared texture from cache, or create from bitmap and assign ID IDriverDependantBitmap *GetSharedDDB(uint32_t sprite_id, Bitmap *bitmap, bool hasAlpha, bool opaque) override; @@ -235,7 +237,7 @@ public: protected: // Create texture data with the given parameters - virtual TextureData *CreateTextureData(int width, int height, bool opaque) = 0; + virtual TextureData *CreateTextureData(int width, int height, bool opaque, bool as_render_target = false) = 0; // Update texture data from the given bitmap virtual void UpdateTextureData(TextureData *txdata, Bitmap *bmp, bool opaque, bool hasAlpha) = 0; // Create DDB using preexisting texture data diff --git a/engines/ags/engine/gfx/graphics_driver.h b/engines/ags/engine/gfx/graphics_driver.h index 58e0e53d047..4234ff1b4ad 100644 --- a/engines/ags/engine/gfx/graphics_driver.h +++ b/engines/ags/engine/gfx/graphics_driver.h @@ -133,11 +133,17 @@ public: // Gets closest recommended bitmap format (currently - only color depth) for the given original format. // Engine needs to have game bitmaps brought to the certain range of formats, easing conversion into the video bitmaps. virtual int GetCompatibleBitmapFormat(int color_depth) = 0; + // Creates a "raw" DDB, without pixel initialization virtual IDriverDependantBitmap *CreateDDB(int width, int height, int color_depth, bool opaque = false) = 0; - // Creates DDB, initializes from the given bitmap + // Creates DDB, initializes from the given bitmap. virtual IDriverDependantBitmap *CreateDDBFromBitmap(Shared::Bitmap *bitmap, bool hasAlpha, bool opaque = false) = 0; + // Creates DDB intended to be used as a render target (allow render other DDBs on it). + virtual IDriverDependantBitmap *CreateRenderTargetDDB(int width, int height, int color_depth, bool opaque = false) = 0; + // Updates DBB using the given bitmap; bitmap must have same size and format + // as the one that this DDB was initialized with. virtual void UpdateDDBFromBitmap(IDriverDependantBitmap *bitmapToUpdate, Shared::Bitmap *bitmap, bool hasAlpha) = 0; + // Destroy the DDB. virtual void DestroyDDB(IDriverDependantBitmap *bitmap) = 0; // Get shared texture from cache, or create from bitmap and assign ID