OpenTTD Source: Blitter Class Reference

OpenTTD Source 13.1

Data Structures | Public Types | Public Member Functions
Blitter Class Referenceabstract

How all blitters should look like. More...

`#include <base.hpp>`

Inheritance diagram for Blitter:

## Data Structures
struct | BlitterParams
| Parameters related to blitting. More...

## Public Types
enum | PaletteAnimation { PALETTE_ANIMATION_NONE, PALETTE_ANIMATION_VIDEO_BACKEND, PALETTE_ANIMATION_BLITTER }
| Types of palette animation. More...

## Public Member Functions
virtual uint8 | GetScreenDepth ()=0
| Get the screen depth this blitter works for. More...
bool | Is32BppSupported () override
| Can the sprite encoder make use of RGBA sprites?
virtual void | Draw (Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)=0
| Draw an image to the screen, given an amount of params defined above.
virtual void | DrawColourMappingRect (void *dst, int width, int height, PaletteID pal)=0
| Draw a colourtable to the screen. More...
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 renderer. More...
virtual void | SetPixel (void *video, int x, int y, uint8 colour)=0
| Draw a pixel with a given colour on the video-buffer. More...
virtual void | DrawRect (void *video, int width, int height, uint8 colour)=0
| Make a single horizontal line in a single colour on the video-buffer. More...
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)=0
| Draw a line with a given colour. More...
virtual void | CopyFromBuffer (void *video, const void *src, int width, int height)=0
| Copy from a buffer to the screen. More...
virtual void | CopyToBuffer (const void *video, void *dst, int width, int height)=0
| Copy from the screen to a buffer. More...
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. More...
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. More...
virtual int | BufferSize (int width, int height)=0
| Calculate how much memory there is needed for an image of this size in the video-buffer. More...
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 the 8bpp palette indexes 'first_dirty' to 'first_dirty + count_dirty'. More...
virtual Blitter::PaletteAnimation | UsePaletteAnimation ()=0
| Check if the blitter uses palette animation at all. More...
virtual bool | NeedsAnimationBuffer ()
| Does this blitter require a separate animation buffer from the video backend?
virtual const char * | GetName ()=0
| Get the name of the blitter, the same as the Factory-instance returns.
virtual int | GetBytesPerPixel ()=0
| Get how many bytes are needed to store a pixel.
virtual void | PostResize ()
| Post resize event.
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)
Public Member Functions inherited from SpriteEncoder
virtual Sprite * | Encode (const SpriteLoader::Sprite *sprite, AllocatorProc *allocator)=0
| Convert a sprite from the loader to our own format.
virtual uint | GetSpriteAlignment ()
| Get the value which the height and width on a sprite have to be aligned by. More...

## Detailed Description

How all blitters should look like.

Extend this class to make your own.

Definition at line 28 of file base.hpp.

## Member Enumeration Documentation

## ◆ PaletteAnimation

enum Blitter::PaletteAnimation

Types of palette animation.

Enumerator
PALETTE_ANIMATION_NONE | No palette animation.
PALETTE_ANIMATION_VIDEO_BACKEND | Palette animation should be done by video backend (8bpp only!)
PALETTE_ANIMATION_BLITTER | The blitter takes care of the palette animation.

Definition at line 49 of file base.hpp.

## Member Function Documentation

## ◆ BufferSize()

virtual int Blitter::BufferSize | ( | int | width,
|  | int | height
| ) |  |
| pure virtual

Calculate how much memory there is needed for an image of this size in the video-buffer.

Parameters

  width | The width of the buffer-to-be.
  height | The height of the buffer-to-be.

Returns
  The size needed for the buffer.

Implemented in Blitter_32bppAnim, Blitter_40bppAnim, Blitter_32bppBase, Blitter_Null, and Blitter_8bppBase.

## ◆ CopyFromBuffer()

virtual void Blitter::CopyFromBuffer | ( | void * | video,
|  | const void * | src,
|  | int | width,
|  | int | height
| ) |  |
| pure virtual

Copy from a buffer to the screen.

Parameters

  video | The destination pointer (video-buffer).
  src | The buffer from which the data will be read.
  width | The width of the buffer.
  height | The height of the buffer.

Note
  You can not do anything with the content of the buffer, as the blitter can store non-pixel data in it too!

Implemented in Blitter_32bppAnim, Blitter_32bppBase, Blitter_Null, Blitter_40bppAnim, and Blitter_8bppBase.

## ◆ CopyImageToBuffer()

virtual void Blitter::CopyImageToBuffer | ( | const void * | video,
|  | void * | dst,
|  | int | width,
|  | int | height,
|  | int | dst_pitch
| ) |  |
| pure virtual

Copy from the screen to a buffer in a palette format for 8bpp and RGBA format for 32bpp.

Parameters

  video | The destination pointer (video-buffer).
  dst | The buffer in which the data will be stored.
  width | The width of the buffer.
  height | The height of the buffer.
  dst_pitch | The pitch (byte per line) of the destination buffer.

Implemented in Blitter_32bppBase, Blitter_Null, Blitter_40bppAnim, and Blitter_8bppBase.

## ◆ CopyToBuffer()

virtual void Blitter::CopyToBuffer | ( | const void * | video,
|  | void * | dst,
|  | int | width,
|  | int | height
| ) |  |
| pure virtual

Copy from the screen to a buffer.

Parameters

  video | The destination pointer (video-buffer).
  dst | The buffer in which the data will be stored.
  width | The width of the buffer.
  height | The height of the buffer.

Note
  You can not do anything with the content of the buffer, as the blitter can store non-pixel data in it too!

Implemented in Blitter_32bppAnim, Blitter_32bppBase, Blitter_Null, Blitter_40bppAnim, and Blitter_8bppBase.

## ◆ DrawColourMappingRect()

virtual void Blitter::DrawColourMappingRect | ( | void * | dst,
|  | int | width,
|  | int | height,
|  | PaletteID | pal
| ) |  |
| pure virtual

Draw a colourtable to the screen.

This is: the colour of the screen is read and is looked-up in the palette to match a new colour, which then is put on the screen again.

Parameters

  dst | the destination pointer (video-buffer).
  width | the width of the buffer.
  height | the height of the buffer.
  pal | the palette to use.

Implemented in Blitter_32bppAnim, Blitter_40bppAnim, Blitter_32bppSimple, Blitter_Null, and Blitter_8bppBase.

## ◆ DrawLine()

virtual void Blitter::DrawLine | ( | void * | video,
|  | int | x,
|  | int | y,
|  | int | x2,
|  | int | y2,
|  | int | screen_width,
|  | int | screen_height,
|  | uint8 | colour,
|  | int | width,
|  | int | dash = `0`
| ) |  |
| pure virtual

Draw a line with a given colour.

Parameters

  video | The destination pointer (video-buffer).
  x | The x coordinate from where the line starts.
  y | The y coordinate from where the line starts.
  x2 | The x coordinate to where the line goes.
  y2 | The y coordinate to where the lines goes.
  screen_width | The width of the screen you are drawing in (to avoid buffer-overflows).
  screen_height | The height of the screen you are drawing in (to avoid buffer-overflows).
  colour | A 8bpp mapping colour.
  width | Line width.
  dash | Length of dashes for dashed lines. 0 means solid line.

Implemented in Blitter_32bppAnim, Blitter_Null, Blitter_32bppBase, Blitter_40bppAnim, and Blitter_8bppBase.

## ◆ DrawRect()

virtual void Blitter::DrawRect | ( | void * | video,
|  | int | width,
|  | int | height,
|  | uint8 | colour
| ) |  |
| pure virtual

Make a single horizontal line in a single colour on the video-buffer.

Parameters

  video | The destination pointer (video-buffer).
  width | The length of the line.
  height | The height of the line.
  colour | A 8bpp mapping colour.

Implemented in Blitter_32bppAnim, Blitter_32bppBase, Blitter_Null, Blitter_40bppAnim, and Blitter_8bppBase.

## ◆ GetScreenDepth()

virtual uint8 Blitter::GetScreenDepth | ( |  | ) |
| pure virtual

Get the screen depth this blitter works for.

This is either: 8, 16, 24 or 32.

Implemented in Blitter_32bppBase, Blitter_8bppBase, and Blitter_Null.

Referenced by VideoDriver_SDL_Default::AllocateBackingStore(), VideoDriver_Win32GDI::AllocateBackingStore(), DrawSpriteToRgbaBuffer(), Is32BppSupported(), MakeLargeWorldScreenshot(), and VideoDriver_Dedicated::Start().

## ◆ MoveTo()

virtual void* Blitter::MoveTo | ( | void * | video,
|  | int | x,
|  | int | y
| ) |  |
| pure virtual

Move the destination pointer the requested amount x and y, keeping in mind any pitch and bpp of the renderer.

Parameters

  video | The destination pointer (video-buffer) to scroll.
  x | How much you want to scroll to the right.
  y | How much you want to scroll to the bottom.

Returns
  A new destination pointer moved the the requested place.

Implemented in Blitter_32bppBase, Blitter_Null, and Blitter_8bppBase.

Referenced by SmallMapWindow::DrawSmallMapColumn().

## ◆ PaletteAnimate()

virtual void Blitter::PaletteAnimate | ( | const Palette & | palette | ) |
| pure virtual

Called when the 8bpp palette is changed; you should redraw all pixels on the screen that are equal to the 8bpp palette indexes 'first_dirty' to 'first_dirty + count_dirty'.

Parameters

  palette | The new palette.

Implemented in Blitter_32bppAnim, Blitter_32bppBase, Blitter_Null, and Blitter_8bppBase.

Referenced by VideoDriver_SDL_Default::Paint(), VideoDriver_SDL_OpenGL::Paint(), and VideoDriver_Win32GDI::Paint().

## ◆ ScrollBuffer()

virtual void Blitter::ScrollBuffer | ( | void * | video,
|  | int & | left,
|  | int & | top,
|  | int & | width,
|  | int & | height,
|  | int | scroll_x,
|  | int | scroll_y
| ) |  |
| pure virtual

Scroll the videobuffer some 'x' and 'y' value.

Parameters

  video | The buffer to scroll into.
  left | The left value of the screen to scroll.
  top | The top value of the screen to scroll.
  width | The width of the screen to scroll.
  height | The height of the screen to scroll.
  scroll_x | How much to scroll in X.
  scroll_y | How much to scroll in Y.

Implemented in Blitter_32bppAnim, Blitter_32bppBase, Blitter_Null, Blitter_40bppAnim, and Blitter_8bppBase.

## ◆ SetPixel()

virtual void Blitter::SetPixel | ( | void * | video,
|  | int | x,
|  | int | y,
|  | uint8 | colour
| ) |  |
| pure virtual

Draw a pixel with a given colour on the video-buffer.

Parameters

  video | The destination pointer (video-buffer).
  x | The x position within video-buffer.
  y | The y position within video-buffer.
  colour | A 8bpp mapping colour.

Implemented in Blitter_32bppAnim, Blitter_32bppBase, Blitter_Null, Blitter_40bppAnim, and Blitter_8bppBase.

## ◆ UsePaletteAnimation()

virtual Blitter::PaletteAnimation Blitter::UsePaletteAnimation | ( |  | ) |
| pure virtual

Check if the blitter uses palette animation at all.

Returns
  True if it uses palette animation.

Implemented in Blitter_32bppAnim, Blitter_40bppAnim, Blitter_32bppBase, Blitter_Null, and Blitter_8bppBase.

Referenced by VideoDriver_SDL::CheckPaletteAnim(), VideoDriver_SDL_Default::Paint(), VideoDriver_SDL_OpenGL::Paint(), and VideoDriver_Win32GDI::Paint().

The documentation for this class was generated from the following files:

- src/blitter/base.hpp
- src/blitter/common.hpp