-
Notifications
You must be signed in to change notification settings - Fork 159
/
ali3dsw.h
268 lines (228 loc) · 9.83 KB
/
ali3dsw.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
//=============================================================================
//
// Adventure Game Studio (AGS)
//
// Copyright (C) 1999-2011 Chris Jones and 2011-20xx others
// The full list of copyright holders can be found in the Copyright.txt
// file, which is part of this source code distribution.
//
// The AGS source code is provided under the Artistic License 2.0.
// A copy of this license can be found in the file License.txt and at
// http://www.opensource.org/licenses/artistic-license-2.0.php
//
//=============================================================================
//
// Software graphics factory, based on Allegro
//
//=============================================================================
#ifndef __AGS_EE_GFX__ALI3DSW_H
#define __AGS_EE_GFX__ALI3DSW_H
#include "util/stdtr1compat.h"
#include TR1INCLUDE(memory)
#include <allegro.h>
#if defined (WINDOWS_VERSION)
#include <winalleg.h>
#include <ddraw.h>
#endif
#include "gfx/bitmap.h"
#include "gfx/ddb.h"
#include "gfx/gfxdriverfactorybase.h"
#include "gfx/gfxdriverbase.h"
namespace AGS
{
namespace Engine
{
namespace ALSW
{
class AllegroGfxFilter;
using AGS::Common::Bitmap;
class ALSoftwareBitmap : public IDriverDependantBitmap
{
public:
// NOTE by CJ:
// Transparency is a bit counter-intuitive
// 0=not transparent, 255=invisible, 1..254 barely visible .. mostly visible
virtual void SetTransparency(int transparency) { _transparency = transparency; }
virtual void SetFlippedLeftRight(bool isFlipped) { _flipped = isFlipped; }
virtual void SetStretch(int width, int height, bool useResampler = true)
{
_stretchToWidth = width;
_stretchToHeight = height;
}
virtual int GetWidth() { return _width; }
virtual int GetHeight() { return _height; }
virtual int GetColorDepth() { return _colDepth; }
virtual void SetLightLevel(int lightLevel) { }
virtual void SetTint(int red, int green, int blue, int tintSaturation) { }
Bitmap *_bmp;
int _width, _height;
int _colDepth;
bool _flipped;
int _stretchToWidth, _stretchToHeight;
bool _opaque;
bool _hasAlpha;
int _transparency;
ALSoftwareBitmap(Bitmap *bmp, bool opaque, bool hasAlpha)
{
_bmp = bmp;
_width = bmp->GetWidth();
_height = bmp->GetHeight();
_colDepth = bmp->GetColorDepth();
_flipped = false;
_stretchToWidth = 0;
_stretchToHeight = 0;
_transparency = 0;
_opaque = opaque;
_hasAlpha = hasAlpha;
}
int GetWidthToRender() { return (_stretchToWidth > 0) ? _stretchToWidth : _width; }
int GetHeightToRender() { return (_stretchToHeight > 0) ? _stretchToHeight : _height; }
void Dispose()
{
// do we want to free the bitmap?
}
~ALSoftwareBitmap()
{
Dispose();
}
};
class ALSoftwareGfxModeList : public IGfxModeList
{
public:
ALSoftwareGfxModeList(GFX_MODE_LIST *alsw_gfx_mode_list)
: _gfxModeList(alsw_gfx_mode_list)
{
}
virtual int GetModeCount() const
{
return _gfxModeList ? _gfxModeList->num_modes : 0;
}
virtual bool GetMode(int index, DisplayMode &mode) const;
private:
GFX_MODE_LIST *_gfxModeList;
};
typedef SpriteDrawListEntry<ALSoftwareBitmap> ALDrawListEntry;
// Software renderer's sprite batch
struct ALSpriteBatch
{
// List of sprites to render
std::vector<ALDrawListEntry> List;
// Intermediate surface which will be drawn upon and transformed if necessary
std::shared_ptr<Bitmap> Surface;
// Tells whether the surface is treated as opaque or transparent
bool Opaque;
};
typedef std::vector<ALSpriteBatch> ALSpriteBatches;
class ALSoftwareGraphicsDriver : public GraphicsDriverBase
{
public:
ALSoftwareGraphicsDriver();
virtual const char*GetDriverName() { return "Software renderer"; }
virtual const char*GetDriverID() { return "Software"; }
virtual void SetTintMethod(TintMethod method);
virtual bool SetDisplayMode(const DisplayMode &mode, volatile int *loopTimer);
virtual bool SetNativeSize(const Size &src_size);
virtual bool SetRenderFrame(const Rect &dst_rect);
virtual bool IsModeSupported(const DisplayMode &mode);
virtual int GetDisplayDepthForNativeDepth(int native_color_depth) const;
virtual IGfxModeList *GetSupportedModeList(int color_depth);
virtual PGfxFilter GetGraphicsFilter() const;
virtual void UnInit();
virtual void ClearRectangle(int x1, int y1, int x2, int y2, RGB *colorToUse);
virtual int GetCompatibleBitmapFormat(int color_depth);
virtual IDriverDependantBitmap* CreateDDBFromBitmap(Bitmap *bitmap, bool hasAlpha, bool opaque);
virtual void UpdateDDBFromBitmap(IDriverDependantBitmap* bitmapToUpdate, Bitmap *bitmap, bool hasAlpha);
virtual void DestroyDDB(IDriverDependantBitmap* bitmap);
virtual void DrawSprite(int x, int y, IDriverDependantBitmap* bitmap);
virtual void RenderToBackBuffer();
virtual void Render();
virtual void Render(GlobalFlipType flip);
virtual bool GetCopyOfScreenIntoBitmap(Bitmap *destination, bool at_native_res, Size *want_size);
virtual void FadeOut(int speed, int targetColourRed, int targetColourGreen, int targetColourBlue);
virtual void FadeIn(int speed, PALETTE pal, int targetColourRed, int targetColourGreen, int targetColourBlue);
virtual void BoxOutEffect(bool blackingOut, int speed, int delay);
virtual bool PlayVideo(const char *filename, bool useAVISound, VideoSkipType skipType, bool stretchToFullScreen);
virtual bool SupportsGammaControl() ;
virtual void SetGamma(int newGamma);
virtual void UseSmoothScaling(bool enabled) { }
virtual void EnableVsyncBeforeRender(bool enabled) { _autoVsync = enabled; }
virtual void Vsync();
virtual void RenderSpritesAtScreenResolution(bool enabled, int supersampling) { }
virtual bool RequiresFullRedrawEachFrame() { return false; }
virtual bool HasAcceleratedTransform() { return false; }
virtual bool UsesMemoryBackBuffer() { return true; }
virtual Bitmap *GetMemoryBackBuffer();
virtual void SetMemoryBackBuffer(Bitmap *backBuffer, int offx, int offy);
virtual Bitmap *GetStageBackBuffer();
virtual void SetScreenTint(int red, int green, int blue) {
_tint_red = red; _tint_green = green; _tint_blue = blue; }
virtual ~ALSoftwareGraphicsDriver();
typedef stdtr1compat::shared_ptr<AllegroGfxFilter> PALSWFilter;
void SetGraphicsFilter(PALSWFilter filter);
private:
PALSWFilter _filter;
bool _autoVsync;
Bitmap *_allegroScreenWrapper;
// Virtual screen bitmap is either a wrapper over Allegro's real screen
// bitmap, or bitmap provided by the graphics filter. It should not be
// disposed by the renderer: it is up to filter object to manage it.
Bitmap *_origVirtualScreen;
// Current virtual screen bitmap; may be provided either by graphics
// filter or by external user. It should not be disposed by the renderer.
Bitmap *virtualScreen;
// Extra offset for the custom virtual screen.
// NOTE: the big issue with software renderer is that it handles main viewport changes
// differently from the hardware-accelerated ones. While D3D and OGL renderers
// work with the full game frame and offset sprites by the viewport's top-left,
// software renderer has to work with "virtual screen" bitmap of the main viewport's size,
// which means that it has to treat 0,0 as a viewport's top-left and not game frame's top-left.
Point _virtualScrOff;
// Stage screen meant for particular rendering stages, may be referencing
// actual virtual screen or separate bitmap of different size that is
// blitted to virtual screen at the stage finalization.
Bitmap *_stageVirtualScreen;
Bitmap *_spareTintingScreen;
int _tint_red, _tint_green, _tint_blue;
ALSpriteBatches _spriteBatches;
GFX_MODE_LIST *_gfxModeList;
#ifdef _WIN32
IDirectDrawGammaControl* dxGammaControl;
// The gamma ramp is a lookup table for each possible R, G and B value
// in 32-bit colour (from 0-255) it maps them to a brightness value
// from 0-65535. The default gamma ramp just multiplies each value by 256
DDGAMMARAMP gammaRamp;
DDGAMMARAMP defaultGammaRamp;
DDCAPS ddrawCaps;
#endif
virtual void InitSpriteBatch(size_t index, const SpriteBatchDesc &desc);
virtual void ResetAllBatches();
// Use gfx filter to create a new virtual screen
void CreateVirtualScreen();
void DestroyVirtualScreen();
// Unset parameters and release resources related to the display mode
void ReleaseDisplayMode();
// Renders single sprite batch on the precreated surface
void RenderSpriteBatch(const ALSpriteBatch &batch, Common::Bitmap *surface, int surf_offx, int surf_offy);
void highcolor_fade_out(int speed, int targetColourRed, int targetColourGreen, int targetColourBlue);
void highcolor_fade_in(Bitmap *bmp_orig, int speed, int targetColourRed, int targetColourGreen, int targetColourBlue);
void __fade_from_range(PALETTE source, PALETTE dest, int speed, int from, int to) ;
void __fade_out_range(int speed, int from, int to, int targetColourRed, int targetColourGreen, int targetColourBlue) ;
int GetAllegroGfxDriverID(bool windowed);
};
class ALSWGraphicsFactory : public GfxDriverFactoryBase<ALSoftwareGraphicsDriver, AllegroGfxFilter>
{
public:
virtual ~ALSWGraphicsFactory();
virtual size_t GetFilterCount() const;
virtual const GfxFilterInfo *GetFilterInfo(size_t index) const;
virtual String GetDefaultFilterID() const;
static ALSWGraphicsFactory *GetFactory();
private:
virtual ALSoftwareGraphicsDriver *EnsureDriverCreated();
virtual AllegroGfxFilter *CreateFilter(const String &id);
static ALSWGraphicsFactory *_factory;
};
} // namespace ALSW
} // namespace Engine
} // namespace AGS
#endif // __AGS_EE_GFX__ALI3DSW_H