OpenTTD Source  20240917-master-g9ab0a47812
base.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * 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.
4  * 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.
5  * 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/>.
6  */
7 
10 #ifndef BLITTER_BASE_HPP
11 #define BLITTER_BASE_HPP
12 
13 #include "../spritecache.h"
14 #include "../spriteloader/spriteloader.hpp"
15 
24 };
25 
29 class Blitter : public SpriteEncoder {
30 public:
32  struct BlitterParams {
33  const void *sprite;
34  const uint8_t *remap;
35 
36  int skip_left;
37  int skip_top;
38  int width;
39  int height;
42  int left;
43  int top;
44 
45  void *dst;
46  int pitch;
47  };
48 
54  };
55 
60  virtual uint8_t GetScreenDepth() = 0;
61 
62  bool Is32BppSupported() override
63  {
64  return this->GetScreenDepth() > 8;
65  }
66 
70  virtual void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) = 0;
71 
81  virtual void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) = 0;
82 
91  virtual void *MoveTo(void *video, int x, int y) = 0;
92 
100  virtual void SetPixel(void *video, int x, int y, uint8_t colour) = 0;
101 
109  virtual void DrawRect(void *video, int width, int height, uint8_t colour) = 0;
110 
124  virtual void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8_t colour, int width, int dash = 0) = 0;
125 
134  virtual void CopyFromBuffer(void *video, const void *src, int width, int height) = 0;
135 
144  virtual void CopyToBuffer(const void *video, void *dst, int width, int height) = 0;
145 
154  virtual void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch) = 0;
155 
166  virtual void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y) = 0;
167 
174  virtual size_t BufferSize(uint width, uint height) = 0;
175 
181  virtual void PaletteAnimate(const Palette &palette) = 0;
182 
188 
192  virtual bool NeedsAnimationBuffer()
193  {
194  return false;
195  }
196 
200  virtual std::string_view GetName() = 0;
201 
205  virtual void PostResize() { };
206 
207  virtual ~Blitter() = default;
208 
209  template <typename SetPixelT> void DrawLineGeneric(int x, int y, int x2, int y2, int screen_width, int screen_height, int width, int dash, SetPixelT set_pixel);
210 };
211 
212 #endif /* BLITTER_BASE_HPP */
Blitter::BlitterParams::top
int top
The top offset in the 'dst' in pixels to start drawing.
Definition: base.hpp:43
BM_TRANSPARENT
@ BM_TRANSPARENT
Perform transparency darkening remapping.
Definition: base.hpp:20
Blitter::DrawColourMappingRect
virtual void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal)=0
Draw a colourtable to the screen.
Blitter::BlitterParams::skip_left
int skip_left
How much pixels of the source to skip on the left (based on zoom of dst)
Definition: base.hpp:36
BlitterMode
BlitterMode
The modes of blitting we can do.
Definition: base.hpp:17
Blitter::BlitterParams::width
int width
The width in pixels that needs to be drawn to dst.
Definition: base.hpp:38
Blitter::UsePaletteAnimation
virtual Blitter::PaletteAnimation UsePaletteAnimation()=0
Check if the blitter uses palette animation at all.
Blitter
How all blitters should look like.
Definition: base.hpp:29
Blitter::BlitterParams::sprite_height
int sprite_height
Real height of the sprite.
Definition: base.hpp:41
Blitter::BlitterParams::remap
const uint8_t * remap
XXX – Temporary storage for remap array.
Definition: base.hpp:34
Blitter::CopyToBuffer
virtual void CopyToBuffer(const void *video, void *dst, int width, int height)=0
Copy from the screen to a buffer.
Blitter::GetScreenDepth
virtual uint8_t GetScreenDepth()=0
Get the screen depth this blitter works for.
Blitter::SetPixel
virtual void SetPixel(void *video, int x, int y, uint8_t colour)=0
Draw a pixel with a given colour on the video-buffer.
Blitter::BlitterParams::dst
void * dst
Destination buffer.
Definition: base.hpp:45
Blitter::ScrollBuffer
virtual void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y)=0
Scroll the videobuffer some 'x' and 'y' value.
Blitter::BlitterParams::sprite_width
int sprite_width
Real width of the sprite.
Definition: base.hpp:40
Blitter::BlitterParams::pitch
int pitch
The pitch of the destination buffer.
Definition: base.hpp:46
PaletteID
uint32_t PaletteID
The number of the palette.
Definition: gfx_type.h:19
BM_NORMAL
@ BM_NORMAL
Perform the simple blitting.
Definition: base.hpp:18
Blitter::BlitterParams::sprite
const void * sprite
Pointer to the sprite how ever the encoder stored it.
Definition: base.hpp:33
Blitter::Draw
virtual void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)=0
Draw an image to the screen, given an amount of params defined above.
Blitter::DrawLine
virtual void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8_t colour, int width, int dash=0)=0
Draw a line with a given colour.
Blitter::NeedsAnimationBuffer
virtual bool NeedsAnimationBuffer()
Does this blitter require a separate animation buffer from the video backend?
Definition: base.hpp:192
Blitter::BufferSize
virtual size_t BufferSize(uint width, uint height)=0
Calculate how much memory there is needed for an image of this size in the video-buffer.
Blitter::PostResize
virtual void PostResize()
Post resize event.
Definition: base.hpp:205
BM_COLOUR_REMAP
@ BM_COLOUR_REMAP
Perform a colour remapping.
Definition: base.hpp:19
BM_CRASH_REMAP
@ BM_CRASH_REMAP
Perform a crash remapping.
Definition: base.hpp:22
SpriteEncoder
Interface for something that can encode a sprite.
Definition: spriteloader.hpp:114
BM_BLACK_REMAP
@ BM_BLACK_REMAP
Perform remapping to a completely blackened sprite.
Definition: base.hpp:23
Blitter::GetName
virtual std::string_view GetName()=0
Get the name of the blitter, the same as the Factory-instance returns.
Blitter::CopyImageToBuffer
virtual void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch)=0
Copy from the screen to a buffer in a palette format for 8bpp and RGBA format for 32bpp.
Blitter::PaletteAnimation
PaletteAnimation
Types of palette animation.
Definition: base.hpp:50
Blitter::Is32BppSupported
bool Is32BppSupported() override
Can the sprite encoder make use of RGBA sprites?
Definition: base.hpp:62
Blitter::MoveTo
virtual void * MoveTo(void *video, int x, int y)=0
Move the destination pointer the requested amount x and y, keeping in mind any pitch and bpp of the r...
Blitter::DrawRect
virtual void DrawRect(void *video, int width, int height, uint8_t colour)=0
Make a single horizontal line in a single colour on the video-buffer.
Blitter::BlitterParams::left
int left
The left offset in the 'dst' in pixels to start drawing.
Definition: base.hpp:42
Blitter::PALETTE_ANIMATION_VIDEO_BACKEND
@ PALETTE_ANIMATION_VIDEO_BACKEND
Palette animation should be done by video backend (8bpp only!)
Definition: base.hpp:52
Blitter::PALETTE_ANIMATION_NONE
@ PALETTE_ANIMATION_NONE
No palette animation.
Definition: base.hpp:51
Blitter::CopyFromBuffer
virtual void CopyFromBuffer(void *video, const void *src, int width, int height)=0
Copy from a buffer to the screen.
Blitter::PaletteAnimate
virtual void PaletteAnimate(const Palette &palette)=0
Called when the 8bpp palette is changed; you should redraw all pixels on the screen that are equal to...
Blitter::BlitterParams
Parameters related to blitting.
Definition: base.hpp:32
Blitter::PALETTE_ANIMATION_BLITTER
@ PALETTE_ANIMATION_BLITTER
The blitter takes care of the palette animation.
Definition: base.hpp:53
Blitter::BlitterParams::height
int height
The height in pixels that needs to be drawn to dst.
Definition: base.hpp:39
Blitter::BlitterParams::skip_top
int skip_top
How much pixels of the source to skip on the top (based on zoom of dst)
Definition: base.hpp:37
Palette
Information about the currently used palette.
Definition: gfx_type.h:330
BM_TRANSPARENT_REMAP
@ BM_TRANSPARENT_REMAP
Perform transparency colour remapping.
Definition: base.hpp:21
ZoomLevel
ZoomLevel
All zoom levels we know.
Definition: zoom_type.h:16