mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r22397) -Document: some tidbits of the blitter code
This commit is contained in:
parent
70c7ec30b1
commit
485c7cd99e
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include "../table/sprites.h"
|
||||
|
||||
/** Instantiation of the 32bpp with animation blitter factory. */
|
||||
static FBlitter_32bppAnim iFBlitter_32bppAnim;
|
||||
|
||||
template <BlitterMode mode>
|
||||
|
|
|
@ -14,11 +14,12 @@
|
|||
|
||||
#include "32bpp_optimized.hpp"
|
||||
|
||||
/** The optimised 32 bpp blitter with palette animation. */
|
||||
class Blitter_32bppAnim : public Blitter_32bppOptimized {
|
||||
private:
|
||||
uint8 *anim_buf; ///< In this buffer we keep track of the 8bpp indexes so we can do palette animation
|
||||
int anim_buf_width;
|
||||
int anim_buf_height;
|
||||
uint8 *anim_buf; ///< In this buffer we keep track of the 8bpp indexes so we can do palette animation
|
||||
int anim_buf_width; ///< The width of the animation buffer.
|
||||
int anim_buf_height; ///< The height of the animation buffer.
|
||||
|
||||
public:
|
||||
Blitter_32bppAnim() :
|
||||
|
@ -45,6 +46,7 @@ public:
|
|||
template <BlitterMode mode> void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom);
|
||||
};
|
||||
|
||||
/** Factory for the 32bpp blitter with animation. */
|
||||
class FBlitter_32bppAnim: public BlitterFactory<FBlitter_32bppAnim> {
|
||||
public:
|
||||
/* virtual */ const char *GetName() { return "32bpp-anim"; }
|
||||
|
|
|
@ -16,12 +16,10 @@
|
|||
#include "../core/bitmath_func.hpp"
|
||||
#include "../gfx_func.h"
|
||||
|
||||
/** Base for all 32bpp blitters. */
|
||||
class Blitter_32bppBase : public Blitter {
|
||||
public:
|
||||
/* virtual */ uint8 GetScreenDepth() { return 32; }
|
||||
// /* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
|
||||
// /* virtual */ void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal);
|
||||
// /* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, AllocatorProc *allocator);
|
||||
/* virtual */ void *MoveTo(const void *video, int x, int y);
|
||||
/* virtual */ void SetPixel(void *video, int x, int y, uint8 colour);
|
||||
/* virtual */ void DrawRect(void *video, int width, int height, uint8 colour);
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "../core/math_func.hpp"
|
||||
#include "32bpp_optimized.hpp"
|
||||
|
||||
/** Instantiation of the optimized 32bpp blitter factory. */
|
||||
static FBlitter_32bppOptimized iFBlitter_32bppOptimized;
|
||||
|
||||
/**
|
||||
|
|
|
@ -14,11 +14,13 @@
|
|||
|
||||
#include "32bpp_simple.hpp"
|
||||
|
||||
/** The optimised 32 bpp blitter (without palette animation). */
|
||||
class Blitter_32bppOptimized : public Blitter_32bppSimple {
|
||||
public:
|
||||
/** Data stored about a (single) sprite. */
|
||||
struct SpriteData {
|
||||
uint32 offset[ZOOM_LVL_COUNT][2];
|
||||
byte data[];
|
||||
uint32 offset[ZOOM_LVL_COUNT][2]; ///< Offsets (from .data) to streams for different zoom levels, and the normal and remap image information.
|
||||
byte data[]; ///< Data, all zoomlevels.
|
||||
};
|
||||
|
||||
/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
|
||||
|
@ -29,6 +31,7 @@ public:
|
|||
template <BlitterMode mode> void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom);
|
||||
};
|
||||
|
||||
/** Factory for the optimised 32 bpp blitter (without palette animation). */
|
||||
class FBlitter_32bppOptimized: public BlitterFactory<FBlitter_32bppOptimized> {
|
||||
public:
|
||||
/* virtual */ const char *GetName() { return "32bpp-optimized"; }
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#include "../table/sprites.h"
|
||||
|
||||
/** Instantiation of the simple 32bpp blitter factory. */
|
||||
static FBlitter_32bppSimple iFBlitter_32bppSimple;
|
||||
|
||||
void Blitter_32bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "32bpp_base.hpp"
|
||||
#include "factory.hpp"
|
||||
|
||||
/** The most trivial 32 bpp blitter (without palette animation). */
|
||||
class Blitter_32bppSimple : public Blitter_32bppBase {
|
||||
public:
|
||||
/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
|
||||
|
@ -24,6 +25,7 @@ public:
|
|||
/* virtual */ const char *GetName() { return "32bpp-simple"; }
|
||||
};
|
||||
|
||||
/** Factory for the simple 32 bpp blitter. */
|
||||
class FBlitter_32bppSimple: public BlitterFactory<FBlitter_32bppSimple> {
|
||||
public:
|
||||
/* virtual */ const char *GetName() { return "32bpp-simple"; }
|
||||
|
|
|
@ -14,12 +14,11 @@
|
|||
|
||||
#include "base.hpp"
|
||||
|
||||
/** Base for all 8bpp blitters. */
|
||||
class Blitter_8bppBase : public Blitter {
|
||||
public:
|
||||
/* virtual */ uint8 GetScreenDepth() { return 8; }
|
||||
// /* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
|
||||
/* virtual */ void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal);
|
||||
// /* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, AllocatorProc *allocator);
|
||||
/* virtual */ void *MoveTo(const void *video, int x, int y);
|
||||
/* virtual */ void SetPixel(void *video, int x, int y, uint8 colour);
|
||||
/* virtual */ void DrawRect(void *video, int width, int height, uint8 colour);
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "../core/random_func.hpp"
|
||||
#include "8bpp_debug.hpp"
|
||||
|
||||
/** Instantiation of the 8bpp debug blitter factory. */
|
||||
static FBlitter_8bppDebug iFBlitter_8bppDebug;
|
||||
|
||||
void Blitter_8bppDebug::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "8bpp_base.hpp"
|
||||
#include "factory.hpp"
|
||||
|
||||
/** 8bpp debug blitter; colours each sprite differently. */
|
||||
class Blitter_8bppDebug : public Blitter_8bppBase {
|
||||
public:
|
||||
/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
|
||||
|
@ -23,6 +24,7 @@ public:
|
|||
/* virtual */ const char *GetName() { return "8bpp-debug"; }
|
||||
};
|
||||
|
||||
/** Factory for the 8bpp debug blitter. */
|
||||
class FBlitter_8bppDebug: public BlitterFactory<FBlitter_8bppDebug> {
|
||||
public:
|
||||
/* virtual */ const char *GetName() { return "8bpp-debug"; }
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "../core/math_func.hpp"
|
||||
#include "8bpp_optimized.hpp"
|
||||
|
||||
/** Instantiation of the 8bpp optimised blitter factory. */
|
||||
static FBlitter_8bppOptimized iFBlitter_8bppOptimized;
|
||||
|
||||
void Blitter_8bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
|
||||
|
|
|
@ -15,11 +15,13 @@
|
|||
#include "8bpp_base.hpp"
|
||||
#include "factory.hpp"
|
||||
|
||||
/** 8bpp blitter optimised for speed. */
|
||||
class Blitter_8bppOptimized : public Blitter_8bppBase {
|
||||
public:
|
||||
/** Data stored about a (single) sprite. */
|
||||
struct SpriteData {
|
||||
uint32 offset[ZOOM_LVL_COUNT]; ///< offsets (from .data) to streams for different zoom levels
|
||||
byte data[]; ///< data, all zoomlevels
|
||||
uint32 offset[ZOOM_LVL_COUNT]; ///< Offsets (from .data) to streams for different zoom levels.
|
||||
byte data[]; ///< Data, all zoomlevels.
|
||||
};
|
||||
|
||||
/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
|
||||
|
@ -28,6 +30,7 @@ public:
|
|||
/* virtual */ const char *GetName() { return "8bpp-optimized"; }
|
||||
};
|
||||
|
||||
/** Factory for the 8bpp blitter optimised for speed. */
|
||||
class FBlitter_8bppOptimized: public BlitterFactory<FBlitter_8bppOptimized> {
|
||||
public:
|
||||
/* virtual */ const char *GetName() { return "8bpp-optimized"; }
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "../zoom_func.h"
|
||||
#include "8bpp_simple.hpp"
|
||||
|
||||
/** Instantiation of the simple 8bpp blitter factory. */
|
||||
static FBlitter_8bppSimple iFBlitter_8bppSimple;
|
||||
|
||||
void Blitter_8bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "8bpp_base.hpp"
|
||||
#include "factory.hpp"
|
||||
|
||||
/** Most trivial 8bpp blitter. */
|
||||
class Blitter_8bppSimple : public Blitter_8bppBase {
|
||||
public:
|
||||
/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
|
||||
|
@ -23,6 +24,7 @@ public:
|
|||
/* virtual */ const char *GetName() { return "8bpp-simple"; }
|
||||
};
|
||||
|
||||
/** Factory for the most trivial 8bpp blitter. */
|
||||
class FBlitter_8bppSimple: public BlitterFactory<FBlitter_8bppSimple> {
|
||||
public:
|
||||
/* virtual */ const char *GetName() { return "8bpp-simple"; }
|
||||
|
|
|
@ -13,18 +13,6 @@
|
|||
#include "base.hpp"
|
||||
#include "../core/math_func.hpp"
|
||||
|
||||
/**
|
||||
* Draw a line with a given colour.
|
||||
* @param video The destination pointer (video-buffer).
|
||||
* @param x The x coordinate from where the line starts.
|
||||
* @param y The y coordinate from where the line starts.
|
||||
* @param x2 The x coordinate to where the line goes.
|
||||
* @param y2 The y coordinate to where the lines goes.
|
||||
* @param screen_width The width of the screen you are drawing in (to avoid buffer-overflows).
|
||||
* @param screen_height The height of the screen you are drawing in (to avoid buffer-overflows).
|
||||
* @param colour A 8bpp mapping colour.
|
||||
* @param width Line width.
|
||||
*/
|
||||
void Blitter::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width)
|
||||
{
|
||||
int dy;
|
||||
|
|
|
@ -15,10 +15,11 @@
|
|||
#include "../spritecache.h"
|
||||
#include "../spriteloader/spriteloader.hpp"
|
||||
|
||||
/** The modes of blitting we can do. */
|
||||
enum BlitterMode {
|
||||
BM_NORMAL,
|
||||
BM_COLOUR_REMAP,
|
||||
BM_TRANSPARENT,
|
||||
BM_NORMAL, ///< Perform the simple blitting.
|
||||
BM_COLOUR_REMAP, ///< Perform a colour remapping.
|
||||
BM_TRANSPARENT, ///< Perform transparency colour remapping.
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -26,20 +27,25 @@ enum BlitterMode {
|
|||
*/
|
||||
class Blitter {
|
||||
public:
|
||||
/** Parameters related to blitting. */
|
||||
struct BlitterParams {
|
||||
const void *sprite; ///< Pointer to the sprite how ever the encoder stored it
|
||||
const byte *remap; ///< XXX -- Temporary storage for remap array
|
||||
const void *sprite; ///< Pointer to the sprite how ever the encoder stored it
|
||||
const byte *remap; ///< XXX -- Temporary storage for remap array
|
||||
|
||||
int skip_left, skip_top; ///< How much pixels of the source to skip on the left and top (based on zoom of dst)
|
||||
int width, height; ///< The width and height in pixels that needs to be drawn to dst
|
||||
int sprite_width; ///< Real width of the sprite
|
||||
int sprite_height; ///< Real height of the sprite
|
||||
int left, top; ///< The offset in the 'dst' in pixels to start drawing
|
||||
int skip_left; ///< How much pixels of the source to skip on the left (based on zoom of dst)
|
||||
int skip_top; ///< How much pixels of the source to skip on the top (based on zoom of dst)
|
||||
int width; ///< The width in pixels that needs to be drawn to dst
|
||||
int height; ///< The height in pixels that needs to be drawn to dst
|
||||
int sprite_width; ///< Real width of the sprite
|
||||
int sprite_height; ///< Real height of the sprite
|
||||
int left; ///< The left offset in the 'dst' in pixels to start drawing
|
||||
int top; ///< The top offset in the 'dst' in pixels to start drawing
|
||||
|
||||
void *dst; ///< Destination buffer
|
||||
int pitch; ///< The pitch of the destination buffer
|
||||
void *dst; ///< Destination buffer
|
||||
int pitch; ///< The pitch of the destination buffer
|
||||
};
|
||||
|
||||
/** Types of palette animation. */
|
||||
enum PaletteAnimation {
|
||||
PALETTE_ANIMATION_NONE, ///< No palette animation
|
||||
PALETTE_ANIMATION_VIDEO_BACKEND, ///< Palette animation should be done by video backend (8bpp only!)
|
||||
|
@ -101,7 +107,19 @@ public:
|
|||
*/
|
||||
virtual void DrawRect(void *video, int width, int height, uint8 colour) = 0;
|
||||
|
||||
void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width);
|
||||
/**
|
||||
* Draw a line with a given colour.
|
||||
* @param video The destination pointer (video-buffer).
|
||||
* @param x The x coordinate from where the line starts.
|
||||
* @param y The y coordinate from where the line starts.
|
||||
* @param x2 The x coordinate to where the line goes.
|
||||
* @param y2 The y coordinate to where the lines goes.
|
||||
* @param screen_width The width of the screen you are drawing in (to avoid buffer-overflows).
|
||||
* @param screen_height The height of the screen you are drawing in (to avoid buffer-overflows).
|
||||
* @param colour A 8bpp mapping colour.
|
||||
* @param width Line width.
|
||||
*/
|
||||
virtual void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width);
|
||||
|
||||
/**
|
||||
* Copy from a buffer to the screen.
|
||||
|
|
|
@ -27,16 +27,24 @@ bool QZ_CanDisplay8bpp();
|
|||
*/
|
||||
class BlitterFactoryBase {
|
||||
private:
|
||||
const char *name;
|
||||
const char *name; ///< The name of the blitter factory.
|
||||
|
||||
typedef std::map<const char *, BlitterFactoryBase *, StringCompare> Blitters;
|
||||
typedef std::map<const char *, BlitterFactoryBase *, StringCompare> Blitters; ///< Map of blitter factories.
|
||||
|
||||
/**
|
||||
* Get the map with currently known blitters.
|
||||
* @return The known blitters.
|
||||
*/
|
||||
static Blitters &GetBlitters()
|
||||
{
|
||||
static Blitters &s_blitters = *new Blitters();
|
||||
return s_blitters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the currently active blitter.
|
||||
* @return The currently active blitter.
|
||||
*/
|
||||
static Blitter **GetActiveBlitter()
|
||||
{
|
||||
static Blitter *s_blitter = NULL;
|
||||
|
@ -121,7 +129,12 @@ public:
|
|||
return *GetActiveBlitter();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fill a buffer with information about the blitters.
|
||||
* @param p The buffer to fill.
|
||||
* @param last The last element of the buffer.
|
||||
* @return p The location till where we filled the buffer.
|
||||
*/
|
||||
static char *GetBlittersInfo(char *p, const char *last)
|
||||
{
|
||||
p += seprintf(p, last, "List of blitters:\n");
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "../stdafx.h"
|
||||
#include "null.hpp"
|
||||
|
||||
/** Instantiation of the null blitter factory. */
|
||||
static FBlitter_Null iFBlitter_Null;
|
||||
|
||||
Sprite *Blitter_Null::Encode(SpriteLoader::Sprite *sprite, AllocatorProc *allocator)
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
#include "factory.hpp"
|
||||
|
||||
/** Blitter that does nothing. */
|
||||
class Blitter_Null : public Blitter {
|
||||
public:
|
||||
/* virtual */ uint8 GetScreenDepth() { return 0; }
|
||||
|
@ -23,7 +24,7 @@ public:
|
|||
/* virtual */ void *MoveTo(const void *video, int x, int y) { return NULL; };
|
||||
/* virtual */ void SetPixel(void *video, int x, int y, uint8 colour) {};
|
||||
/* virtual */ void DrawRect(void *video, int width, int height, uint8 colour) {};
|
||||
/* virtual */ void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour) {};
|
||||
/* virtual */ void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width) {};
|
||||
/* virtual */ void CopyFromBuffer(void *video, const void *src, int width, int height) {};
|
||||
/* virtual */ void CopyToBuffer(const void *video, void *dst, int width, int height) {};
|
||||
/* virtual */ void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch) {};
|
||||
|
@ -36,6 +37,7 @@ public:
|
|||
/* virtual */ int GetBytesPerPixel() { return 0; }
|
||||
};
|
||||
|
||||
/** Factory for the blitter that doesn nothing. */
|
||||
class FBlitter_Null: public BlitterFactory<FBlitter_Null> {
|
||||
public:
|
||||
/* virtual */ const char *GetName() { return "null"; }
|
||||
|
|
|
@ -16,20 +16,20 @@
|
|||
#include "video/video_driver.hpp"
|
||||
#include "string_func.h"
|
||||
|
||||
VideoDriver *_video_driver;
|
||||
char *_ini_videodriver;
|
||||
int _num_resolutions;
|
||||
Dimension _resolutions[32];
|
||||
Dimension _cur_resolution;
|
||||
bool _rightclick_emulate;
|
||||
VideoDriver *_video_driver; ///< The currently active video driver.
|
||||
char *_ini_videodriver; ///< The video driver a stored in the configuration file.
|
||||
int _num_resolutions; ///< The number of resolutions.
|
||||
Dimension _resolutions[32]; ///< List of resolutions.
|
||||
Dimension _cur_resolution; ///< The current resolution.
|
||||
bool _rightclick_emulate; ///< Whether right clicking is emulated.
|
||||
|
||||
SoundDriver *_sound_driver;
|
||||
char *_ini_sounddriver;
|
||||
SoundDriver *_sound_driver; ///< The currently active sound driver.
|
||||
char *_ini_sounddriver; ///< The sound driver a stored in the configuration file.
|
||||
|
||||
MusicDriver *_music_driver;
|
||||
char *_ini_musicdriver;
|
||||
MusicDriver *_music_driver; ///< The currently active music driver.
|
||||
char *_ini_musicdriver; ///< The music driver a stored in the configuration file.
|
||||
|
||||
char *_ini_blitter;
|
||||
char *_ini_blitter; ///< The blitter as stored in the configuration file.
|
||||
|
||||
const char *GetDriverParam(const char * const *parm, const char *name)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue