ScummVM API documentation
draw_software.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// Software drawing component. Optimizes drawing for software renderer using
25// dirty rectangles technique.
26//
27//=============================================================================
28
29#ifndef AGS_ENGINE_AC_DRAW_SOFTWARE_H
30#define AGS_ENGINE_AC_DRAW_SOFTWARE_H
31
32#include "ags/shared/gfx/bitmap.h"
33#include "ags/engine/gfx/ddb.h"
34#include "ags/shared/util/geometry.h"
35#include "ags/shared/util/scaling.h"
36
37namespace AGS3 {
38
39using AGS::Shared::PlaneScaling;
40
41// TODO: choose these values depending on game resolution?
42#define MAXDIRTYREGIONS 25
43#define WHOLESCREENDIRTY (MAXDIRTYREGIONS + 5)
44#define MAX_SPANS_PER_ROW 4
45
46// Dirty rects store coordinate values in the coordinate system of a camera surface,
47// where coords always span from 0,0 to surface width,height.
48// Converting from room to dirty rects would require subtracting room camera offsets.
49struct IRSpan {
50 int x1, x2;
51 int mergeSpan(int tx1, int tx2);
52
53 IRSpan();
54};
55
56struct IRRow {
57 IRSpan span[MAX_SPANS_PER_ROW];
58 int numSpans;
59
60 IRRow();
61};
62
63struct DirtyRects {
64 // Size of the surface managed by this dirty rects object
65 Size SurfaceSize;
66 // Where the surface is rendered on screen
68 // Room -> screen coordinate transformation
69 PlaneScaling Room2Screen;
70 // Screen -> dirty surface rect
71 // The dirty rects are saved in coordinates limited to (0,0)->(camera size) rather than room or screen coords
72 PlaneScaling Screen2DirtySurf;
73
74 std::vector<IRRow> DirtyRows;
75 Rect DirtyRegions[MAXDIRTYREGIONS];
76 size_t NumDirtyRegions;
77
78 DirtyRects();
79 bool IsInit() const;
80 // Initialize dirty rects for the given surface size
81 void Init(const Size &surf_size, const Rect &viewport);
82 void SetSurfaceOffsets(int x, int y);
83 // Delete dirty rects
84 void Destroy();
85 // Mark all surface as tidy
86 void Reset();
87};
88
89// Sets global viewport offset (used for legacy letterbox)
90void set_invalidrects_globaloffs(int x, int y);
91// Inits dirty rects array for the given room camera/viewport pair
92// View_index indicates the room viewport (>= 0) or the main viewport (-1)
93void init_invalid_regions(int view_index, const Size &surf_size, const Rect &viewport);
94// Deletes dirty rects for particular index
95void delete_invalid_regions(int view_index);
96// Disposes dirty rects arrays
97void dispose_invalid_regions(bool room_only);
98// Update the coordinate transformation for the particular dirty rects object
99void set_invalidrects_cameraoffs(int view_index, int x, int y);
100// Mark the whole screen dirty
101void invalidate_all_rects();
102// Mark the whole camera surface dirty
103void invalidate_all_camera_rects(int view_index);
104// Mark certain rectangle dirty; in_room tells if coordinates are room viewport or screen coords
105void invalidate_rect_ds(int x1, int y1, int x2, int y2, bool in_room);
106// Mark rectangle dirty, treat pos as global screen coords (not offset by legacy letterbox mode)
107void invalidate_rect_global(int x1, int y1, int x2, int y2);
108// Paints the black screen background in the regions marked as dirty
109void update_black_invreg_and_reset(AGS::Shared::Bitmap *ds);
110// Copies the room regions marked as dirty from source (src) to destination (ds) with the given offset (x, y)
111// no_transform flag tells the system that the regions should be plain copied to the ds.
112void update_room_invreg_and_reset(int view_index, AGS::Shared::Bitmap *ds, AGS::Shared::Bitmap *src, bool no_transform);
113
114} // namespace AGS3
115
116#endif
Definition: allegro_bitmap.h:44
Definition: viewport.h:128
Definition: vector.h:39
Definition: scaling.h:108
Definition: draw_software.h:63
Definition: draw_software.h:56
Definition: draw_software.h:49
Definition: geometry.h:219
Definition: geometry.h:148