4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
10 /** @file base.hpp Base for all blitters. */
12 #ifndef BLITTER_BASE_HPP
13 #define BLITTER_BASE_HPP
15 #include "../spritecache.h"
16 #include "../spriteloader/spriteloader.hpp"
18 /** The modes of blitting we can do. */
20 BM_NORMAL
, ///< Perform the simple blitting.
21 BM_COLOUR_REMAP
, ///< Perform a colour remapping.
22 BM_TRANSPARENT
, ///< Perform transparency colour remapping.
23 BM_CRASH_REMAP
, ///< Perform a crash remapping.
24 BM_BLACK_REMAP
, ///< Perform remapping to a completely blackened sprite
28 * How all blitters should look like. Extend this class to make your own.
32 /** Parameters related to blitting. */
33 struct BlitterParams
{
34 const void *sprite
; ///< Pointer to the sprite how ever the encoder stored it
35 const byte
*remap
; ///< XXX -- Temporary storage for remap array
37 int skip_left
; ///< How much pixels of the source to skip on the left (based on zoom of dst)
38 int skip_top
; ///< How much pixels of the source to skip on the top (based on zoom of dst)
39 int width
; ///< The width in pixels that needs to be drawn to dst
40 int height
; ///< The height in pixels that needs to be drawn to dst
41 int sprite_width
; ///< Real width of the sprite
42 int sprite_height
; ///< Real height of the sprite
43 int left
; ///< The left offset in the 'dst' in pixels to start drawing
44 int top
; ///< The top offset in the 'dst' in pixels to start drawing
46 void *dst
; ///< Destination buffer
47 int pitch
; ///< The pitch of the destination buffer
50 /** Types of palette animation. */
51 enum PaletteAnimation
{
52 PALETTE_ANIMATION_NONE
, ///< No palette animation
53 PALETTE_ANIMATION_VIDEO_BACKEND
, ///< Palette animation should be done by video backend (8bpp only!)
54 PALETTE_ANIMATION_BLITTER
, ///< The blitter takes care of the palette animation
58 * Get the screen depth this blitter works for.
59 * This is either: 8, 16, 24 or 32.
61 virtual uint8
GetScreenDepth() = 0;
64 * Draw an image to the screen, given an amount of params defined above.
66 virtual void Draw(Blitter::BlitterParams
*bp
, BlitterMode mode
, ZoomLevel zoom
) = 0;
69 * Draw a colourtable to the screen. This is: the colour of the screen is read
70 * and is looked-up in the palette to match a new colour, which then is put
71 * on the screen again.
72 * @param dst the destination pointer (video-buffer).
73 * @param width the width of the buffer.
74 * @param height the height of the buffer.
75 * @param pal the palette to use.
77 virtual void DrawColourMappingRect(void *dst
, int width
, int height
, PaletteID pal
) = 0;
80 * Convert a sprite from the loader to our own format.
82 virtual Sprite
*Encode(const SpriteLoader::Sprite
*sprite
, AllocatorProc
*allocator
) = 0;
85 * Move the destination pointer the requested amount x and y, keeping in mind
86 * any pitch and bpp of the renderer.
87 * @param video The destination pointer (video-buffer) to scroll.
88 * @param x How much you want to scroll to the right.
89 * @param y How much you want to scroll to the bottom.
90 * @return A new destination pointer moved the the requested place.
92 virtual void *MoveTo(void *video
, int x
, int y
) = 0;
95 * Draw a pixel with a given colour on the video-buffer.
96 * @param video The destination pointer (video-buffer).
97 * @param x The x position within video-buffer.
98 * @param y The y position within video-buffer.
99 * @param colour A 8bpp mapping colour.
101 virtual void SetPixel(void *video
, int x
, int y
, uint8 colour
) = 0;
104 * Make a single horizontal line in a single colour on the video-buffer.
105 * @param video The destination pointer (video-buffer).
106 * @param width The length of the line.
107 * @param height The height of the line.
108 * @param colour A 8bpp mapping colour.
110 virtual void DrawRect(void *video
, int width
, int height
, uint8 colour
) = 0;
113 * Draw a line with a given colour.
114 * @param video The destination pointer (video-buffer).
115 * @param x The x coordinate from where the line starts.
116 * @param y The y coordinate from where the line starts.
117 * @param x2 The x coordinate to where the line goes.
118 * @param y2 The y coordinate to where the lines goes.
119 * @param screen_width The width of the screen you are drawing in (to avoid buffer-overflows).
120 * @param screen_height The height of the screen you are drawing in (to avoid buffer-overflows).
121 * @param colour A 8bpp mapping colour.
122 * @param width Line width.
123 * @param dash Length of dashes for dashed lines. 0 means solid line.
125 virtual void DrawLine(void *video
, int x
, int y
, int x2
, int y2
, int screen_width
, int screen_height
, uint8 colour
, int width
, int dash
= 0);
128 * Copy from a buffer to the screen.
129 * @param video The destination pointer (video-buffer).
130 * @param src The buffer from which the data will be read.
131 * @param width The width of the buffer.
132 * @param height The height of the buffer.
133 * @note You can not do anything with the content of the buffer, as the blitter can store non-pixel data in it too!
135 virtual void CopyFromBuffer(void *video
, const void *src
, int width
, int height
) = 0;
138 * Copy from the screen to a buffer.
139 * @param video The destination pointer (video-buffer).
140 * @param dst The buffer in which the data will be stored.
141 * @param width The width of the buffer.
142 * @param height The height of the buffer.
143 * @note You can not do anything with the content of the buffer, as the blitter can store non-pixel data in it too!
145 virtual void CopyToBuffer(const void *video
, void *dst
, int width
, int height
) = 0;
148 * Copy from the screen to a buffer in a palette format for 8bpp and RGBA format for 32bpp.
149 * @param video The destination pointer (video-buffer).
150 * @param dst The buffer in which the data will be stored.
151 * @param width The width of the buffer.
152 * @param height The height of the buffer.
153 * @param dst_pitch The pitch (byte per line) of the destination buffer.
155 virtual void CopyImageToBuffer(const void *video
, void *dst
, int width
, int height
, int dst_pitch
) = 0;
158 * Scroll the videobuffer some 'x' and 'y' value.
159 * @param video The buffer to scroll into.
160 * @param left The left value of the screen to scroll.
161 * @param top The top value of the screen to scroll.
162 * @param width The width of the screen to scroll.
163 * @param height The height of the screen to scroll.
164 * @param scroll_x How much to scroll in X.
165 * @param scroll_y How much to scroll in Y.
167 virtual void ScrollBuffer(void *video
, int &left
, int &top
, int &width
, int &height
, int scroll_x
, int scroll_y
) = 0;
170 * Calculate how much memory there is needed for an image of this size in the video-buffer.
171 * @param width The width of the buffer-to-be.
172 * @param height The height of the buffer-to-be.
173 * @return The size needed for the buffer.
175 virtual int BufferSize(int width
, int height
) = 0;
178 * Called when the 8bpp palette is changed; you should redraw all pixels on the screen that
179 * are equal to the 8bpp palette indexes 'first_dirty' to 'first_dirty + count_dirty'.
180 * @param palette The new palette.
182 virtual void PaletteAnimate(const Palette
&palette
) = 0;
185 * Check if the blitter uses palette animation at all.
186 * @return True if it uses palette animation.
188 virtual Blitter::PaletteAnimation
UsePaletteAnimation() = 0;
191 * Get the name of the blitter, the same as the Factory-instance returns.
193 virtual const char *GetName() = 0;
196 * Get how many bytes are needed to store a pixel.
198 virtual int GetBytesPerPixel() = 0;
203 virtual void PostResize() { };
205 virtual ~Blitter() { }
208 #endif /* BLITTER_BASE_HPP */