1
0
Fork 0

(svn r22397) -Document: some tidbits of the blitter code

release/1.2
rubidium 2011-05-01 10:15:33 +00:00
parent 70c7ec30b1
commit 485c7cd99e
20 changed files with 91 additions and 52 deletions

View File

@ -16,6 +16,7 @@
#include "../table/sprites.h" #include "../table/sprites.h"
/** Instantiation of the 32bpp with animation blitter factory. */
static FBlitter_32bppAnim iFBlitter_32bppAnim; static FBlitter_32bppAnim iFBlitter_32bppAnim;
template <BlitterMode mode> template <BlitterMode mode>

View File

@ -14,11 +14,12 @@
#include "32bpp_optimized.hpp" #include "32bpp_optimized.hpp"
/** The optimised 32 bpp blitter with palette animation. */
class Blitter_32bppAnim : public Blitter_32bppOptimized { class Blitter_32bppAnim : public Blitter_32bppOptimized {
private: private:
uint8 *anim_buf; ///< In this buffer we keep track of the 8bpp indexes so we can do palette animation 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_width; ///< The width of the animation buffer.
int anim_buf_height; int anim_buf_height; ///< The height of the animation buffer.
public: public:
Blitter_32bppAnim() : Blitter_32bppAnim() :
@ -45,6 +46,7 @@ public:
template <BlitterMode mode> void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom); 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> { class FBlitter_32bppAnim: public BlitterFactory<FBlitter_32bppAnim> {
public: public:
/* virtual */ const char *GetName() { return "32bpp-anim"; } /* virtual */ const char *GetName() { return "32bpp-anim"; }

View File

@ -16,12 +16,10 @@
#include "../core/bitmath_func.hpp" #include "../core/bitmath_func.hpp"
#include "../gfx_func.h" #include "../gfx_func.h"
/** Base for all 32bpp blitters. */
class Blitter_32bppBase : public Blitter { class Blitter_32bppBase : public Blitter {
public: public:
/* virtual */ uint8 GetScreenDepth() { return 32; } /* 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 *MoveTo(const void *video, int x, int y);
/* virtual */ void SetPixel(void *video, int x, int y, uint8 colour); /* virtual */ void SetPixel(void *video, int x, int y, uint8 colour);
/* virtual */ void DrawRect(void *video, int width, int height, uint8 colour); /* virtual */ void DrawRect(void *video, int width, int height, uint8 colour);

View File

@ -14,6 +14,7 @@
#include "../core/math_func.hpp" #include "../core/math_func.hpp"
#include "32bpp_optimized.hpp" #include "32bpp_optimized.hpp"
/** Instantiation of the optimized 32bpp blitter factory. */
static FBlitter_32bppOptimized iFBlitter_32bppOptimized; static FBlitter_32bppOptimized iFBlitter_32bppOptimized;
/** /**

View File

@ -14,11 +14,13 @@
#include "32bpp_simple.hpp" #include "32bpp_simple.hpp"
/** The optimised 32 bpp blitter (without palette animation). */
class Blitter_32bppOptimized : public Blitter_32bppSimple { class Blitter_32bppOptimized : public Blitter_32bppSimple {
public: public:
/** Data stored about a (single) sprite. */
struct SpriteData { struct SpriteData {
uint32 offset[ZOOM_LVL_COUNT][2]; uint32 offset[ZOOM_LVL_COUNT][2]; ///< Offsets (from .data) to streams for different zoom levels, and the normal and remap image information.
byte data[]; byte data[]; ///< Data, all zoomlevels.
}; };
/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom); /* 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); 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> { class FBlitter_32bppOptimized: public BlitterFactory<FBlitter_32bppOptimized> {
public: public:
/* virtual */ const char *GetName() { return "32bpp-optimized"; } /* virtual */ const char *GetName() { return "32bpp-optimized"; }

View File

@ -15,6 +15,7 @@
#include "../table/sprites.h" #include "../table/sprites.h"
/** Instantiation of the simple 32bpp blitter factory. */
static FBlitter_32bppSimple iFBlitter_32bppSimple; static FBlitter_32bppSimple iFBlitter_32bppSimple;
void Blitter_32bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) void Blitter_32bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)

View File

@ -15,6 +15,7 @@
#include "32bpp_base.hpp" #include "32bpp_base.hpp"
#include "factory.hpp" #include "factory.hpp"
/** The most trivial 32 bpp blitter (without palette animation). */
class Blitter_32bppSimple : public Blitter_32bppBase { class Blitter_32bppSimple : public Blitter_32bppBase {
public: public:
/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom); /* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
@ -24,6 +25,7 @@ public:
/* virtual */ const char *GetName() { return "32bpp-simple"; } /* virtual */ const char *GetName() { return "32bpp-simple"; }
}; };
/** Factory for the simple 32 bpp blitter. */
class FBlitter_32bppSimple: public BlitterFactory<FBlitter_32bppSimple> { class FBlitter_32bppSimple: public BlitterFactory<FBlitter_32bppSimple> {
public: public:
/* virtual */ const char *GetName() { return "32bpp-simple"; } /* virtual */ const char *GetName() { return "32bpp-simple"; }

View File

@ -14,12 +14,11 @@
#include "base.hpp" #include "base.hpp"
/** Base for all 8bpp blitters. */
class Blitter_8bppBase : public Blitter { class Blitter_8bppBase : public Blitter {
public: public:
/* virtual */ uint8 GetScreenDepth() { return 8; } /* 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 */ 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 *MoveTo(const void *video, int x, int y);
/* virtual */ void SetPixel(void *video, int x, int y, uint8 colour); /* virtual */ void SetPixel(void *video, int x, int y, uint8 colour);
/* virtual */ void DrawRect(void *video, int width, int height, uint8 colour); /* virtual */ void DrawRect(void *video, int width, int height, uint8 colour);

View File

@ -14,6 +14,7 @@
#include "../core/random_func.hpp" #include "../core/random_func.hpp"
#include "8bpp_debug.hpp" #include "8bpp_debug.hpp"
/** Instantiation of the 8bpp debug blitter factory. */
static FBlitter_8bppDebug iFBlitter_8bppDebug; static FBlitter_8bppDebug iFBlitter_8bppDebug;
void Blitter_8bppDebug::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) void Blitter_8bppDebug::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)

View File

@ -15,6 +15,7 @@
#include "8bpp_base.hpp" #include "8bpp_base.hpp"
#include "factory.hpp" #include "factory.hpp"
/** 8bpp debug blitter; colours each sprite differently. */
class Blitter_8bppDebug : public Blitter_8bppBase { class Blitter_8bppDebug : public Blitter_8bppBase {
public: public:
/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom); /* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
@ -23,6 +24,7 @@ public:
/* virtual */ const char *GetName() { return "8bpp-debug"; } /* virtual */ const char *GetName() { return "8bpp-debug"; }
}; };
/** Factory for the 8bpp debug blitter. */
class FBlitter_8bppDebug: public BlitterFactory<FBlitter_8bppDebug> { class FBlitter_8bppDebug: public BlitterFactory<FBlitter_8bppDebug> {
public: public:
/* virtual */ const char *GetName() { return "8bpp-debug"; } /* virtual */ const char *GetName() { return "8bpp-debug"; }

View File

@ -14,6 +14,7 @@
#include "../core/math_func.hpp" #include "../core/math_func.hpp"
#include "8bpp_optimized.hpp" #include "8bpp_optimized.hpp"
/** Instantiation of the 8bpp optimised blitter factory. */
static FBlitter_8bppOptimized iFBlitter_8bppOptimized; static FBlitter_8bppOptimized iFBlitter_8bppOptimized;
void Blitter_8bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) void Blitter_8bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)

View File

@ -15,11 +15,13 @@
#include "8bpp_base.hpp" #include "8bpp_base.hpp"
#include "factory.hpp" #include "factory.hpp"
/** 8bpp blitter optimised for speed. */
class Blitter_8bppOptimized : public Blitter_8bppBase { class Blitter_8bppOptimized : public Blitter_8bppBase {
public: public:
/** Data stored about a (single) sprite. */
struct SpriteData { struct SpriteData {
uint32 offset[ZOOM_LVL_COUNT]; ///< offsets (from .data) to streams for different zoom levels uint32 offset[ZOOM_LVL_COUNT]; ///< Offsets (from .data) to streams for different zoom levels.
byte data[]; ///< data, all zoomlevels byte data[]; ///< Data, all zoomlevels.
}; };
/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom); /* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
@ -28,6 +30,7 @@ public:
/* virtual */ const char *GetName() { return "8bpp-optimized"; } /* virtual */ const char *GetName() { return "8bpp-optimized"; }
}; };
/** Factory for the 8bpp blitter optimised for speed. */
class FBlitter_8bppOptimized: public BlitterFactory<FBlitter_8bppOptimized> { class FBlitter_8bppOptimized: public BlitterFactory<FBlitter_8bppOptimized> {
public: public:
/* virtual */ const char *GetName() { return "8bpp-optimized"; } /* virtual */ const char *GetName() { return "8bpp-optimized"; }

View File

@ -13,6 +13,7 @@
#include "../zoom_func.h" #include "../zoom_func.h"
#include "8bpp_simple.hpp" #include "8bpp_simple.hpp"
/** Instantiation of the simple 8bpp blitter factory. */
static FBlitter_8bppSimple iFBlitter_8bppSimple; static FBlitter_8bppSimple iFBlitter_8bppSimple;
void Blitter_8bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) void Blitter_8bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)

View File

@ -15,6 +15,7 @@
#include "8bpp_base.hpp" #include "8bpp_base.hpp"
#include "factory.hpp" #include "factory.hpp"
/** Most trivial 8bpp blitter. */
class Blitter_8bppSimple : public Blitter_8bppBase { class Blitter_8bppSimple : public Blitter_8bppBase {
public: public:
/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom); /* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
@ -23,6 +24,7 @@ public:
/* virtual */ const char *GetName() { return "8bpp-simple"; } /* virtual */ const char *GetName() { return "8bpp-simple"; }
}; };
/** Factory for the most trivial 8bpp blitter. */
class FBlitter_8bppSimple: public BlitterFactory<FBlitter_8bppSimple> { class FBlitter_8bppSimple: public BlitterFactory<FBlitter_8bppSimple> {
public: public:
/* virtual */ const char *GetName() { return "8bpp-simple"; } /* virtual */ const char *GetName() { return "8bpp-simple"; }

View File

@ -13,18 +13,6 @@
#include "base.hpp" #include "base.hpp"
#include "../core/math_func.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) 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; int dy;

View File

@ -15,10 +15,11 @@
#include "../spritecache.h" #include "../spritecache.h"
#include "../spriteloader/spriteloader.hpp" #include "../spriteloader/spriteloader.hpp"
/** The modes of blitting we can do. */
enum BlitterMode { enum BlitterMode {
BM_NORMAL, BM_NORMAL, ///< Perform the simple blitting.
BM_COLOUR_REMAP, BM_COLOUR_REMAP, ///< Perform a colour remapping.
BM_TRANSPARENT, BM_TRANSPARENT, ///< Perform transparency colour remapping.
}; };
/** /**
@ -26,20 +27,25 @@ enum BlitterMode {
*/ */
class Blitter { class Blitter {
public: public:
/** Parameters related to blitting. */
struct BlitterParams { struct BlitterParams {
const void *sprite; ///< Pointer to the sprite how ever the encoder stored it const void *sprite; ///< Pointer to the sprite how ever the encoder stored it
const byte *remap; ///< XXX -- Temporary storage for remap array 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 skip_left; ///< How much pixels of the source to skip on the left (based on zoom of dst)
int width, height; ///< The width and height in pixels that needs to be drawn to dst int skip_top; ///< How much pixels of the source to skip on the top (based on zoom of dst)
int sprite_width; ///< Real width of the sprite int width; ///< The width in pixels that needs to be drawn to dst
int sprite_height; ///< Real height of the sprite int height; ///< The height in pixels that needs to be drawn to dst
int left, top; ///< The offset in the 'dst' in pixels to start drawing 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 void *dst; ///< Destination buffer
int pitch; ///< The pitch of the destination buffer int pitch; ///< The pitch of the destination buffer
}; };
/** Types of palette animation. */
enum PaletteAnimation { enum PaletteAnimation {
PALETTE_ANIMATION_NONE, ///< No palette animation PALETTE_ANIMATION_NONE, ///< No palette animation
PALETTE_ANIMATION_VIDEO_BACKEND, ///< Palette animation should be done by video backend (8bpp only!) 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; 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. * Copy from a buffer to the screen.

View File

@ -27,16 +27,24 @@ bool QZ_CanDisplay8bpp();
*/ */
class BlitterFactoryBase { class BlitterFactoryBase {
private: 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 &GetBlitters()
{ {
static Blitters &s_blitters = *new Blitters(); static Blitters &s_blitters = *new Blitters();
return s_blitters; return s_blitters;
} }
/**
* Get the currently active blitter.
* @return The currently active blitter.
*/
static Blitter **GetActiveBlitter() static Blitter **GetActiveBlitter()
{ {
static Blitter *s_blitter = NULL; static Blitter *s_blitter = NULL;
@ -121,7 +129,12 @@ public:
return *GetActiveBlitter(); 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) static char *GetBlittersInfo(char *p, const char *last)
{ {
p += seprintf(p, last, "List of blitters:\n"); p += seprintf(p, last, "List of blitters:\n");

View File

@ -12,6 +12,7 @@
#include "../stdafx.h" #include "../stdafx.h"
#include "null.hpp" #include "null.hpp"
/** Instantiation of the null blitter factory. */
static FBlitter_Null iFBlitter_Null; static FBlitter_Null iFBlitter_Null;
Sprite *Blitter_Null::Encode(SpriteLoader::Sprite *sprite, AllocatorProc *allocator) Sprite *Blitter_Null::Encode(SpriteLoader::Sprite *sprite, AllocatorProc *allocator)

View File

@ -14,6 +14,7 @@
#include "factory.hpp" #include "factory.hpp"
/** Blitter that does nothing. */
class Blitter_Null : public Blitter { class Blitter_Null : public Blitter {
public: public:
/* virtual */ uint8 GetScreenDepth() { return 0; } /* virtual */ uint8 GetScreenDepth() { return 0; }
@ -23,7 +24,7 @@ public:
/* virtual */ void *MoveTo(const void *video, int x, int y) { return NULL; }; /* 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 SetPixel(void *video, int x, int y, uint8 colour) {};
/* virtual */ void DrawRect(void *video, int width, int height, 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 CopyFromBuffer(void *video, const void *src, int width, int height) {};
/* virtual */ void CopyToBuffer(const void *video, void *dst, 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) {}; /* 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; } /* virtual */ int GetBytesPerPixel() { return 0; }
}; };
/** Factory for the blitter that doesn nothing. */
class FBlitter_Null: public BlitterFactory<FBlitter_Null> { class FBlitter_Null: public BlitterFactory<FBlitter_Null> {
public: public:
/* virtual */ const char *GetName() { return "null"; } /* virtual */ const char *GetName() { return "null"; }

View File

@ -16,20 +16,20 @@
#include "video/video_driver.hpp" #include "video/video_driver.hpp"
#include "string_func.h" #include "string_func.h"
VideoDriver *_video_driver; VideoDriver *_video_driver; ///< The currently active video driver.
char *_ini_videodriver; char *_ini_videodriver; ///< The video driver a stored in the configuration file.
int _num_resolutions; int _num_resolutions; ///< The number of resolutions.
Dimension _resolutions[32]; Dimension _resolutions[32]; ///< List of resolutions.
Dimension _cur_resolution; Dimension _cur_resolution; ///< The current resolution.
bool _rightclick_emulate; bool _rightclick_emulate; ///< Whether right clicking is emulated.
SoundDriver *_sound_driver; SoundDriver *_sound_driver; ///< The currently active sound driver.
char *_ini_sounddriver; char *_ini_sounddriver; ///< The sound driver a stored in the configuration file.
MusicDriver *_music_driver; MusicDriver *_music_driver; ///< The currently active music driver.
char *_ini_musicdriver; 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) const char *GetDriverParam(const char * const *parm, const char *name)
{ {