ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 
105  // Tells if this gfx driver has to redraw whole scene each time
106  virtual bool RequiresFullRedrawEachFrame() = 0;
107  // Tells if this gfx driver uses GPU to transform sprites
108  virtual bool HasAcceleratedTransform() = 0;
109  // Tells if this gfx driver draws on a virtual screen before rendering on real screen.
110  virtual bool UsesMemoryBackBuffer() = 0;
111  // Tells if this gfx driver requires releasing render targets
112  // in case of display mode change or reset.
113  virtual bool ShouldReleaseRenderTargets() = 0;
114 
115  virtual void SetTintMethod(TintMethod method) = 0;
116  // Initialize given display mode
117  virtual bool SetDisplayMode(const DisplayMode &mode) = 0;
118  // Updates previously set display mode, accommodating to the new screen size
119  virtual void UpdateDeviceScreen(const Size &screen_size) = 0;
120  // Gets if a graphics mode was initialized
121  virtual bool IsModeSet() const = 0;
122  // Set the size of the native image size
123  virtual bool SetNativeResolution(const GraphicResolution &native_res) = 0;
124  virtual bool IsNativeSizeValid() const = 0;
125  // Set game render frame and translation
126  virtual bool SetRenderFrame(const Rect &dst_rect) = 0;
127  virtual bool IsRenderFrameValid() const = 0;
128  // Report which color depth options are best suited for the given native color depth
129  virtual int GetDisplayDepthForNativeDepth(int native_color_depth) const = 0;
130  virtual IGfxModeList *GetSupportedModeList(int color_depth) = 0;
131  virtual bool IsModeSupported(const DisplayMode &mode) = 0;
132  virtual DisplayMode GetDisplayMode() const = 0;
133  virtual PGfxFilter GetGraphicsFilter() const = 0;
134  virtual Size GetNativeSize() const = 0;
135  virtual Rect GetRenderDestination() const = 0;
136  virtual void SetCallbackForPolling(GFXDRV_CLIENTCALLBACK callback) = 0;
137  // TODO: get rid of draw screen callback at some point when all fade functions are more or less grouped in one
138  virtual void SetCallbackToDrawScreen(GFXDRV_CLIENTCALLBACK callback, GFXDRV_CLIENTCALLBACK post_callback) = 0;
139  virtual void SetCallbackOnInit(GFXDRV_CLIENTCALLBACKINITGFX callback) = 0;
140  // The event callback is called in the main render loop when a
141  // event entry is encountered inside a sprite list.
142  // You can use this to hook into the rendering process.
143  virtual void SetCallbackOnSpriteEvt(GFXDRV_CLIENTCALLBACKEVT callback) = 0;
144  // Clears the screen rectangle. The coordinates are expected in the **native game resolution**.
145  virtual void ClearRectangle(int x1, int y1, int x2, int y2, RGB *colorToUse) = 0;
146  // Gets closest recommended bitmap format (currently - only color depth) for the given original format.
147  // Engine needs to have game bitmaps brought to the certain range of formats, easing conversion into the video bitmaps.
148  virtual int GetCompatibleBitmapFormat(int color_depth) = 0;
149  // Returns available texture memory, or 0 if this query is not supported
150  virtual size_t GetAvailableTextureMemory() = 0;
151 
152  // Creates a "raw" DDB, without pixel initialization
153  virtual IDriverDependantBitmap *CreateDDB(int width, int height, int color_depth, bool opaque = false) = 0;
154  // Creates DDB, initializes from the given bitmap.
155  virtual IDriverDependantBitmap *CreateDDBFromBitmap(Shared::Bitmap *bitmap, bool has_alpha, bool opaque = false) = 0;
156  // Creates DDB intended to be used as a render target (allow render other DDBs on it).
157  virtual IDriverDependantBitmap *CreateRenderTargetDDB(int width, int height, int color_depth, bool opaque = false) = 0;
158  // Updates DBB using the given bitmap; bitmap must have same size and format
159  // as the one that this DDB was initialized with.
160  virtual void UpdateDDBFromBitmap(IDriverDependantBitmap *bitmapToUpdate, Shared::Bitmap *bitmap, bool has_alpha) = 0;
161  // Destroy the DDB.
162  virtual void DestroyDDB(IDriverDependantBitmap *bitmap) = 0;
163 
164  // Get shared texture from cache, or create from bitmap and assign ID
165  // FIXME: opaque should be either texture data's flag, - in which case same sprite_id
166  // will be either opaque or not opaque, - or DDB's flag, but in that case it cannot
167  // be applied to the shared texture data. Currently it's possible to share same
168  // texture data, but update it with different "opaque" values, which breaks logic.
169  virtual IDriverDependantBitmap *GetSharedDDB(uint32_t sprite_id,
170  Shared::Bitmap *bitmap = nullptr, bool has_alpha = true, bool opaque = false) = 0;
171  virtual void UpdateSharedDDB(uint32_t sprite_id, Shared::Bitmap *bitmap = nullptr, bool has_alpha = true, bool opaque = false) = 0;
172  // Removes the shared texture reference, will force the texture to recreate next time
173  virtual void ClearSharedDDB(uint32_t sprite_id) = 0;
174 
175  // Prepares next sprite batch, a list of sprites with defined viewport and optional
176  // global model transformation; all subsequent calls to DrawSprite will be adding
177  // sprites to this batch's list.
178  // Beginning a batch while the previous was not ended will create a sub-batch
179  // (think of it as of a child scene node).
180  // Optionally you can assign "filter flags" to this batch; this lets to filter certain
181  // batches out during some operations, such as fading effects or making screenshots.
182  virtual void BeginSpriteBatch(const Rect &viewport, const SpriteTransform &transform = SpriteTransform(),
183  Shared::GraphicFlip flip = Shared::kFlip_None, PBitmap surface = nullptr, uint32_t filter_flags = 0) = 0;
184  // Ends current sprite batch
185  virtual void EndSpriteBatch() = 0;
186  // Adds sprite to the active batch
187  virtual void DrawSprite(int x, int y, IDriverDependantBitmap *bitmap) = 0;
188  // Adds fade overlay fx to the active batch
189  virtual void SetScreenFade(int red, int green, int blue) = 0;
190  // Adds tint overlay fx to the active batch
191  // TODO: redesign this to allow various post-fx per sprite batch?
192  virtual void SetScreenTint(int red, int green, int blue) = 0;
193  // Sets stage screen parameters for the current batch.
194  // Currently includes size and optional position offset;
195  // the position is relative, as stage screens are using sprite batch transforms.
196  // Stage screens are used to let plugins do raw drawing during render callbacks.
197  // TODO: find a better term? note, it's used in several places around renderers.
198  virtual void SetStageScreen(const Size &sz, int x = 0, int y = 0) = 0;
199  // Clears all sprite batches, resets batch counter
200  virtual void ClearDrawLists() = 0;
201  virtual void RenderToBackBuffer() = 0;
202  virtual void Render() = 0;
203  // Renders with additional final offset and flip
204  // TODO: leftover from old code, solely for software renderer; remove when
205  // software mode either discarded or scene node graph properly implemented.
206  virtual void Render(int xoff, int yoff, Shared::GraphicFlip flip) = 0;
207  // Copies contents of the game screen into bitmap using simple blit or pixel copy.
208  // Bitmap must be of supported size and pixel format. If it's not the method will
209  // fail and optionally write wanted destination format into 'want_fmt' pointer.
210  virtual bool GetCopyOfScreenIntoBitmap(Shared::Bitmap *destination, const Rect *src_rect, bool at_native_res,
211  GraphicResolution *want_fmt = nullptr, uint32_t batch_skip_filter = 0u) = 0;
212  // Tells if the renderer supports toggling vsync after initializing the mode.
213  virtual bool DoesSupportVsyncToggle() = 0;
214  // Toggles vertical sync mode, if renderer supports one; returns the *new state*.
215  virtual bool SetVsync(bool enabled) = 0;
216  // Tells if the renderer currently has vsync enabled.
217  virtual bool GetVsync() const = 0;
218  // Enables or disables rendering mode that draws sprite list directly into
219  // the final resolution, as opposed to drawing to native-resolution buffer
220  // and scaling to final frame. The effect may be that sprites that are
221  // drawn with additional fractional scaling will appear more detailed than
222  // the rest of the game. The effect is stronger for the low-res games being
223  // rendered in the high-res mode.
224  virtual void RenderSpritesAtScreenResolution(bool enabled) = 0;
225  // TODO: move fade-in/out/boxout functions out of the graphics driver!! make everything render through
226  // main drawing procedure. Since currently it does not - we need to init our own sprite batch
227  // internally to let it set up correct viewport settings instead of relying on a chance.
228  // Runs fade-out animation in a blocking manner.
229  virtual void FadeOut(int speed, int targetColourRed, int targetColourGreen, int targetColourBlue,
230  uint32_t batch_skip_filter = 0u) = 0;
231  // Runs fade-in animation in a blocking manner.
232  virtual void FadeIn(int speed, PALETTE p, int targetColourRed, int targetColourGreen, int targetColourBlue,
233  uint32_t batch_skip_filter = 0u) = 0;
234  // Runs box-out animation in a blocking manner.
235  virtual void BoxOutEffect(bool blackingOut, int speed, int delay, uint32_t batch_skip_filter = 0u) = 0;
236  virtual void UseSmoothScaling(bool enabled) = 0;
237  virtual bool SupportsGammaControl() = 0;
238  virtual void SetGamma(int newGamma) = 0;
239  // Returns the virtual screen. Will return NULL if renderer does not support memory backbuffer.
240  // In normal case you should use GetStageBackBuffer() instead.
241  virtual Shared::Bitmap *GetMemoryBackBuffer() = 0;
242  // Sets custom backbuffer bitmap to render to.
243  // Passing NULL pointer will tell renderer to switch back to its original virtual screen.
244  // Note that only software renderer supports this.
245  virtual void SetMemoryBackBuffer(Shared::Bitmap *backBuffer) = 0;
246  // Returns memory backbuffer for the current rendering stage (or base virtual screen if called outside of render pass).
247  // All renderers should support this.
248  virtual Shared::Bitmap *GetStageBackBuffer(bool mark_dirty = false) = 0;
249  // Sets custom backbuffer bitmap to render current render stage to.
250  // Passing NULL pointer will tell renderer to switch back to its original stage buffer.
251  // Note that only software renderer supports this.
252  virtual void SetStageBackBuffer(Shared::Bitmap *backBuffer) = 0;
253  // Retrieves 3 transform matrixes for the current rendering stage: world (model), view and projection.
254  // These matrixes will be filled in accordance to the renderer's compatible format;
255  // returns false if renderer does not use matrixes (not a 3D renderer).
256  virtual bool GetStageMatrixes(RenderMatrixes &rm) = 0;
257 
258  virtual ~IGraphicsDriver() {}
259 };
260 
261 } // namespace Engine
262 } // namespace AGS
263 } // namespace AGS3
264 
265 #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:219
Definition: color.h:49
Definition: geometry.h:148
Definition: gfx_defines.h:33
Definition: gfx_mode_list.h:38
Definition: ptr.h:159
Definition: engine.h:144
Definition: graphics_driver.h:85
Definition: ags.h:40