ScummVM API documentation
graphics_driver.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 //=============================================================================
23 //
24 // Graphics driver interface
25 //
26 //=============================================================================
27 
28 #ifndef AGS_ENGINE_GFX_GRAPHICS_DRIVER_H
29 #define AGS_ENGINE_GFX_GRAPHICS_DRIVER_H
30 
31 //#include "math/matrix.h"
32 #include "common/std/memory.h"
33 #include "ags/lib/allegro.h" // RGB, PALETTE
34 #include "ags/shared/gfx/gfx_def.h"
35 #include "ags/engine/gfx/gfx_defines.h"
36 #include "ags/engine/gfx/gfx_mode_list.h"
37 #include "ags/shared/util/geometry.h"
38 
39 namespace AGS3 {
40 namespace AGS {
41 
42 namespace Shared {
43 class Bitmap;
44 typedef std::shared_ptr<Shared::Bitmap> PBitmap;
45 } // namespace Shared
46 
47 namespace Engine {
48 
49 // Forward declaration
50 class IDriverDependantBitmap;
51 class IGfxFilter;
52 typedef std::shared_ptr<IGfxFilter> PGfxFilter;
53 using Shared::PBitmap;
54 
55 enum TintMethod {
56  TintReColourise = 0,
57  TintSpecifyMaximum = 1
58 };
59 
61  int Alpha = 255; // alpha color value (0 - 255)
62 
63  SpriteColorTransform() = default;
64  SpriteColorTransform(int alpha) : Alpha(alpha) {
65  }
66 };
67 
68 // Sprite transformation
69 // TODO: combine with stretch parameters in the IDriverDependantBitmap?
71  // Translate
72  int X = 0, Y = 0;
73  float ScaleX = 1.f, ScaleY = 1.f;
74  float Rotate = 0.f; // angle, in radians
76 
77  SpriteTransform() = default;
78  SpriteTransform(int x, int y, float scalex = 1.0f, float scaley = 1.0f, float rotate = 0.0f,
80  : X(x), Y(y), ScaleX(scalex), ScaleY(scaley), Rotate(rotate), Color(color) {
81  }
82 };
83 
84 // Describes 3 render matrixes: world, view and projection
86  /*
87  glm::mat4 World;
88  glm::mat4 View;
89  glm::mat4 Projection;
90  */
91 };
92 
93 
94 typedef void (*GFXDRV_CLIENTCALLBACK)();
95 typedef bool (*GFXDRV_CLIENTCALLBACKEVT)(int evt, int data);
96 typedef void (*GFXDRV_CLIENTCALLBACKINITGFX)(void *data);
97 
99 public:
100  // Gets graphic driver's identifier
101  virtual const char *GetDriverID() = 0;
102  // Gets graphic driver's "friendly name"
103  virtual const char *GetDriverName() = 0;
104  virtual void SetTintMethod(TintMethod method) = 0;
105  // Initialize given display mode
106  virtual bool SetDisplayMode(const DisplayMode &mode) = 0;
107  // Updates previously set display mode, accommodating to the new screen size
108  virtual void UpdateDeviceScreen(const Size &screen_size) = 0;
109  // Gets if a graphics mode was initialized
110  virtual bool IsModeSet() const = 0;
111  // Set the size of the native image size
112  virtual bool SetNativeResolution(const GraphicResolution &native_res) = 0;
113  virtual bool IsNativeSizeValid() const = 0;
114  // Set game render frame and translation
115  virtual bool SetRenderFrame(const Rect &dst_rect) = 0;
116  virtual bool IsRenderFrameValid() const = 0;
117  // Report which color depth options are best suited for the given native color depth
118  virtual int GetDisplayDepthForNativeDepth(int native_color_depth) const = 0;
119  virtual IGfxModeList *GetSupportedModeList(int color_depth) = 0;
120  virtual bool IsModeSupported(const DisplayMode &mode) = 0;
121  virtual DisplayMode GetDisplayMode() const = 0;
122  virtual PGfxFilter GetGraphicsFilter() const = 0;
123  virtual Size GetNativeSize() const = 0;
124  virtual Rect GetRenderDestination() const = 0;
125  virtual void SetCallbackForPolling(GFXDRV_CLIENTCALLBACK callback) = 0;
126  // TODO: get rid of draw screen callback at some point when all fade functions are more or less grouped in one
127  virtual void SetCallbackToDrawScreen(GFXDRV_CLIENTCALLBACK callback, GFXDRV_CLIENTCALLBACK post_callback) = 0;
128  virtual void SetCallbackOnInit(GFXDRV_CLIENTCALLBACKINITGFX callback) = 0;
129  // The event callback is called in the main render loop when a
130  // event entry is encountered inside a sprite list.
131  // You can use this to hook into the rendering process.
132  virtual void SetCallbackOnSpriteEvt(GFXDRV_CLIENTCALLBACKEVT callback) = 0;
133  // Clears the screen rectangle. The coordinates are expected in the **native game resolution**.
134  virtual void ClearRectangle(int x1, int y1, int x2, int y2, RGB *colorToUse) = 0;
135  // Gets closest recommended bitmap format (currently - only color depth) for the given original format.
136  // Engine needs to have game bitmaps brought to the certain range of formats, easing conversion into the video bitmaps.
137  virtual int GetCompatibleBitmapFormat(int color_depth) = 0;
138 
139  // Creates a "raw" DDB, without pixel initialization
140  virtual IDriverDependantBitmap *CreateDDB(int width, int height, int color_depth, bool opaque = false) = 0;
141  // Creates DDB, initializes from the given bitmap.
142  virtual IDriverDependantBitmap *CreateDDBFromBitmap(Shared::Bitmap *bitmap, bool hasAlpha, bool opaque = false) = 0;
143  // Creates DDB intended to be used as a render target (allow render other DDBs on it).
144  virtual IDriverDependantBitmap *CreateRenderTargetDDB(int width, int height, int color_depth, bool opaque = false) = 0;
145  // Updates DBB using the given bitmap; bitmap must have same size and format
146  // as the one that this DDB was initialized with.
147  virtual void UpdateDDBFromBitmap(IDriverDependantBitmap *bitmapToUpdate, Shared::Bitmap *bitmap, bool hasAlpha) = 0;
148  // Destroy the DDB.
149  virtual void DestroyDDB(IDriverDependantBitmap *bitmap) = 0;
150 
151  // Get shared texture from cache, or create from bitmap and assign ID
152  virtual IDriverDependantBitmap *GetSharedDDB(uint32_t sprite_id,
153  Shared::Bitmap *bitmap = nullptr, bool hasAlpha = true, bool opaque = false) = 0;
154  virtual void UpdateSharedDDB(uint32_t sprite_id, Shared::Bitmap *bitmap = nullptr, bool hasAlpha = true, bool opaque = false) = 0;
155  // Removes the shared texture reference, will force the texture to recreate next time
156  virtual void ClearSharedDDB(uint32_t sprite_id) = 0;
157 
158  // Prepares next sprite batch, a list of sprites with defined viewport and optional
159  // global model transformation; all subsequent calls to DrawSprite will be adding
160  // sprites to this batch's list.
161  // Beginning a batch while the previous was not ended will create a sub-batch
162  // (think of it as of a child scene node).
163  virtual void BeginSpriteBatch(const Rect &viewport, const SpriteTransform &transform = SpriteTransform(),
164  Shared::GraphicFlip flip = Shared::kFlip_None, PBitmap surface = nullptr) = 0;
165  // Ends current sprite batch
166  virtual void EndSpriteBatch() = 0;
167  // Adds sprite to the active batch
168  virtual void DrawSprite(int x, int y, IDriverDependantBitmap *bitmap) = 0;
169  // Adds fade overlay fx to the active batch
170  virtual void SetScreenFade(int red, int green, int blue) = 0;
171  // Adds tint overlay fx to the active batch
172  // TODO: redesign this to allow various post-fx per sprite batch?
173  virtual void SetScreenTint(int red, int green, int blue) = 0;
174  // Sets stage screen parameters for the current batch.
175  // Currently includes size and optional position offset;
176  // the position is relative, as stage screens are using sprite batch transforms.
177  // Stage screens are used to let plugins do raw drawing during render callbacks.
178  // TODO: find a better term? note, it's used in several places around renderers.
179  virtual void SetStageScreen(const Size &sz, int x = 0, int y = 0) = 0;
180  // Clears all sprite batches, resets batch counter
181  virtual void ClearDrawLists() = 0;
182  virtual void RenderToBackBuffer() = 0;
183  virtual void Render() = 0;
184  // Renders with additional final offset and flip
185  // TODO: leftover from old code, solely for software renderer; remove when
186  // software mode either discarded or scene node graph properly implemented.
187  virtual void Render(int xoff, int yoff, Shared::GraphicFlip flip) = 0;
188  // Copies contents of the game screen into bitmap using simple blit or pixel copy.
189  // Bitmap must be of supported size and pixel format. If it's not the method will
190  // fail and optionally write wanted destination format into 'want_fmt' pointer.
191  virtual bool GetCopyOfScreenIntoBitmap(Shared::Bitmap *destination, bool at_native_res, GraphicResolution *want_fmt = nullptr) = 0;
192  // Tells if the renderer supports toggling vsync after initializing the mode.
193  virtual bool DoesSupportVsyncToggle() = 0;
194  // Toggles vertical sync mode, if renderer supports one; returns the *new state*.
195  virtual bool SetVsync(bool enabled) = 0;
196  // Tells if the renderer currently has vsync enabled.
197  virtual bool GetVsync() const = 0;
198  // Enables or disables rendering mode that draws sprite list directly into
199  // the final resolution, as opposed to drawing to native-resolution buffer
200  // and scaling to final frame. The effect may be that sprites that are
201  // drawn with additional fractional scaling will appear more detailed than
202  // the rest of the game. The effect is stronger for the low-res games being
203  // rendered in the high-res mode.
204  virtual void RenderSpritesAtScreenResolution(bool enabled, int supersampling = 1) = 0;
205  // TODO: move fade-in/out/boxout functions out of the graphics driver!! make everything render through
206  // main drawing procedure. Since currently it does not - we need to init our own sprite batch
207  // internally to let it set up correct viewport settings instead of relying on a chance.
208  // Runs fade-out animation in a blocking manner.
209  virtual void FadeOut(int speed, int targetColourRed, int targetColourGreen, int targetColourBlue) = 0;
210  // Runs fade-in animation in a blocking manner.
211  virtual void FadeIn(int speed, PALETTE p, int targetColourRed, int targetColourGreen, int targetColourBlue) = 0;
212  // Runs box-out animation in a blocking manner.
213  virtual void BoxOutEffect(bool blackingOut, int speed, int delay) = 0;
214  virtual void UseSmoothScaling(bool enabled) = 0;
215  virtual bool SupportsGammaControl() = 0;
216  virtual void SetGamma(int newGamma) = 0;
217  // Returns the virtual screen. Will return NULL if renderer does not support memory backbuffer.
218  // In normal case you should use GetStageBackBuffer() instead.
219  virtual Shared::Bitmap *GetMemoryBackBuffer() = 0;
220  // Sets custom backbuffer bitmap to render to.
221  // Passing NULL pointer will tell renderer to switch back to its original virtual screen.
222  // Note that only software renderer supports this.
223  virtual void SetMemoryBackBuffer(Shared::Bitmap *backBuffer) = 0;
224  // Returns memory backbuffer for the current rendering stage (or base virtual screen if called outside of render pass).
225  // All renderers should support this.
226  virtual Shared::Bitmap *GetStageBackBuffer(bool mark_dirty = false) = 0;
227  // Sets custom backbuffer bitmap to render current render stage to.
228  // Passing NULL pointer will tell renderer to switch back to its original stage buffer.
229  // Note that only software renderer supports this.
230  virtual void SetStageBackBuffer(Shared::Bitmap *backBuffer) = 0;
231  // Retrieves 3 transform matrixes for the current rendering stage: world (model), view and projection.
232  // These matrixes will be filled in accordance to the renderer's compatible format;
233  // returns false if renderer does not use matrixes (not a 3D renderer).
234  virtual bool GetStageMatrixes(RenderMatrixes &rm) = 0;
235  virtual bool RequiresFullRedrawEachFrame() = 0;
236  virtual bool HasAcceleratedTransform() = 0;
237  virtual bool UsesMemoryBackBuffer() = 0;
238  virtual ~IGraphicsDriver() {}
239 };
240 
241 } // namespace Engine
242 } // namespace AGS
243 } // namespace AGS3
244 
245 #endif
Definition: achievements_tables.h:27
Definition: graphics_driver.h:70
Definition: allegro_bitmap.h:44
Definition: gfx_defines.h:60
Definition: graphics_driver.h:60
Definition: graphics_driver.h:98
Definition: geometry.h:215
Definition: color.h:49
Definition: geometry.h:144
Definition: gfx_defines.h:33
Definition: gfx_mode_list.h:38
Definition: ptr.h:159
Definition: engine.h:143
Definition: graphics_driver.h:85
Definition: ags.h:40