(svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter

-Codechange: introduced a hierachy of blitters to avoid a lot of code duplication
 Note: this allows much easier adding other types of video-drivers, like OpenGL
This commit is contained in:
truelight
2007-06-17 20:30:28 +00:00
parent b0b4820387
commit 003375d375
39 changed files with 486 additions and 627 deletions

125
src/blitter/32bpp_base.cpp Normal file
View File

@@ -0,0 +1,125 @@
#include "../stdafx.h"
#include "../gfx.h"
#include "32bpp_base.hpp"
void *Blitter_32bppBase::MoveTo(const void *video, int x, int y)
{
return (uint32 *)video + x + y * _screen.pitch;
}
void Blitter_32bppBase::SetPixel(void *video, int x, int y, uint8 color)
{
*((uint32 *)video + x + y * _screen.pitch) = LookupColourInPalette(color);
}
void Blitter_32bppBase::SetPixelIfEmpty(void *video, int x, int y, uint8 color)
{
uint32 *dst = (uint32 *)video + x + y * _screen.pitch;
if (*dst == 0) *dst = LookupColourInPalette(color);
}
void Blitter_32bppBase::SetHorizontalLine(void *video, int width, uint8 color)
{
uint32 *dst = (uint32 *)video;
uint32 color32 = LookupColourInPalette(color);
for (; width > 0; width--) {
*dst = color32;
dst++;
}
}
void Blitter_32bppBase::DrawLine(void *video, int x, int y, int x2, int y2, uint8 color)
{
int dy;
int dx;
int stepx;
int stepy;
int frac;
dy = (y2 - y) * 2;
if (dy < 0) {
dy = -dy;
stepy = -1;
} else {
stepy = 1;
}
dx = (x2 - x) * 2;
if (dx < 0) {
dx = -dx;
stepx = -1;
} else {
stepx = 1;
}
this->SetPixel(video, x, y, color);
if (dx > dy) {
frac = dy - (dx >> 1);
while (x != x2) {
if (frac >= 0) {
y += stepy;
frac -= dx;
}
x += stepx;
frac += dy;
this->SetPixel(video, x, y, color);
}
} else {
frac = dx - (dy >> 1);
while (y != y2) {
if (frac >= 0) {
x += stepx;
frac -= dy;
}
y += stepy;
frac += dx;
this->SetPixel(video, x, y, color);
}
}
}
void Blitter_32bppBase::CopyFromBuffer(void *video, const void *src, int width, int height, int src_pitch)
{
int direction = (height < 0) ? -1 : 1;
uint32 *dst = (uint32 *)video;
uint32 *usrc = (uint32 *)src;
height = abs(height);
for (; height > 0; height--) {
memcpy(dst, usrc, width * sizeof(uint32));
usrc += src_pitch * direction;
dst += _screen.pitch * direction;
}
}
void Blitter_32bppBase::CopyToBuffer(const void *video, void *dst, int width, int height, int dst_pitch)
{
int direction = (height < 0) ? -1 : 1;
uint32 *udst = (uint32 *)dst;
uint32 *src = (uint32 *)video;
height = abs(height);
for (; height > 0; height--) {
memcpy(udst, src, width * sizeof(uint32));
src += _screen.pitch * direction;
udst += dst_pitch * direction;
}
}
void Blitter_32bppBase::MoveBuffer(void *video_dst, const void *video_src, int width, int height)
{
uint32 *dst = (uint32 *)video_dst;
uint32 *src = (uint32 *)video_src;
for (; height > 0; height--) {
memmove(dst, src, width * sizeof(uint32));
src += _screen.pitch;
dst += _screen.pitch;
}
}
int Blitter_32bppBase::BufferSize(int width, int height)
{
return width * height * sizeof(uint32);
}

View File

@@ -0,0 +1,33 @@
/* $Id$ */
/** @file 32bpp_base.hpp */
#ifndef BLITTER_32BPP_BASE_HPP
#define BLITTER_32BPP_BASE_HPP
#include "base.hpp"
class Blitter_32bppBase : public Blitter {
public:
/* virtual */ uint8 GetScreenDepth() { return 32; }
// /* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
// /* virtual */ void DrawColorMappingRect(void *dst, int width, int height, int pal);
// /* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator);
/* virtual */ void *MoveTo(const void *video, int x, int y);
/* virtual */ void SetPixel(void *video, int x, int y, uint8 color);
/* virtual */ void SetPixelIfEmpty(void *video, int x, int y, uint8 color);
/* virtual */ void SetHorizontalLine(void *video, int width, uint8 color);
/* virtual */ void DrawLine(void *video, int x, int y, int x2, int y2, uint8 color);
/* virtual */ void CopyFromBuffer(void *video, const void *src, int width, int height, int src_pitch);
/* virtual */ void CopyToBuffer(const void *video, void *dst, int width, int height, int dst_pitch);
/* virtual */ void MoveBuffer(void *video_dst, const void *video_src, int width, int height);
/* virtual */ int BufferSize(int width, int height);
static inline uint32 LookupColourInPalette(uint8 index) {
#define ARGB(a, r, g, b) ((((a) << 24) & 0xFF000000) | (((r) << 16) & 0x00FF0000) | (((g) << 8) & 0x0000FF00) | ((b) & 0x000000FF))
if (index == 0) return 0x00000000;
return ARGB(0xFF, _cur_palette[index].r, _cur_palette[index].g, _cur_palette[index].b);
}
};
#endif /* BLITTER_32BPP_BASE_HPP */

View File

@@ -3,7 +3,6 @@
#include "../gfx.h"
#include "../debug.h"
#include "../table/sprites.h"
#include "../renderer/32bpp.hpp"
#include "32bpp_simple.hpp"
static FBlitter_32bppSimple iFBlitter_32bppSimple;
@@ -108,7 +107,7 @@ void Blitter_32bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Zoo
if (src->m == 0) {
if (src->a != 0) *dst = ComposeColorRGBA(src->r, src->g, src->b, src->a, *dst);
} else {
if (bp->remap[src->m] != 0) *dst = ComposeColorPA(Renderer_32bpp::LookupColourInPalette(bp->remap[src->m]), src->a, *dst);
if (bp->remap[src->m] != 0) *dst = ComposeColorPA(this->LookupColourInPalette(bp->remap[src->m]), src->a, *dst);
}
break;
@@ -176,7 +175,7 @@ Sprite *Blitter_32bppSimple::Encode(SpriteLoader::Sprite *sprite, Blitter::Alloc
for (int i = 0; i < sprite->height * sprite->width; i++) {
if (dst[i].m != 0) {
/* Pre-convert the mapping channel to a RGB value */
uint color = Renderer_32bpp::LookupColourInPalette(dst[i].m);
uint color = this->LookupColourInPalette(dst[i].m);
dst[i].r = GB(color, 16, 8);
dst[i].g = GB(color, 8, 8);
dst[i].b = GB(color, 0, 8);

View File

@@ -5,27 +5,20 @@
#ifndef BLITTER_32BPP_SIMPLE_HPP
#define BLITTER_32BPP_SIMPLE_HPP
#include "blitter.hpp"
#include "32bpp_base.hpp"
#include "factory.hpp"
class Blitter_32bppSimple : public Blitter {
class Blitter_32bppSimple : public Blitter_32bppBase {
public:
/* virtual */ uint8 GetScreenDepth() { return 32; }
/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
/* virtual */ void DrawColorMappingRect(void *dst, int width, int height, int pal);
/* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator);
/* virtual */ const char *GetRenderer() { return "32bpp"; }
};
class FBlitter_32bppSimple: public BlitterFactory<FBlitter_32bppSimple> {
public:
/* virtual */ const char *GetName() { return "32bpp-simple"; }
/* virtual */ const char *GetDescription() { return "32bpp Simple Blitter (no palette animation)"; }
/* virtual */ Blitter *CreateInstance() { return new Blitter_32bppSimple(); }
};

129
src/blitter/8bpp_base.cpp Normal file
View File

@@ -0,0 +1,129 @@
#include "../stdafx.h"
#include "../gfx.h"
#include "8bpp_base.hpp"
void Blitter_8bppBase::DrawColorMappingRect(void *dst, int width, int height, int pal)
{
const uint8 *ctab = GetNonSprite(pal) + 1;
do {
for (int i = 0; i != width; i++) *((uint8 *)dst + i) = ctab[((uint8 *)dst)[i]];
dst = (uint8 *)dst + _screen.pitch;
} while (height--);
}
void *Blitter_8bppBase::MoveTo(const void *video, int x, int y)
{
return (uint8 *)video + x + y * _screen.pitch;
}
void Blitter_8bppBase::SetPixel(void *video, int x, int y, uint8 color)
{
*((uint8 *)video + x + y * _screen.pitch) = color;
}
void Blitter_8bppBase::SetPixelIfEmpty(void *video, int x, int y, uint8 color)
{
uint8 *dst = (uint8 *)video + x + y * _screen.pitch;
if (*dst == 0) *dst = color;
}
void Blitter_8bppBase::SetHorizontalLine(void *video, int width, uint8 color)
{
memset(video, color, width);
}
void Blitter_8bppBase::DrawLine(void *video, int x, int y, int x2, int y2, uint8 color)
{
int dy;
int dx;
int stepx;
int stepy;
int frac;
dy = (y2 - y) * 2;
if (dy < 0) {
dy = -dy;
stepy = -1;
} else {
stepy = 1;
}
dx = (x2 - x) * 2;
if (dx < 0) {
dx = -dx;
stepx = -1;
} else {
stepx = 1;
}
this->SetPixel(video, x, y, color);
if (dx > dy) {
frac = dy - (dx / 2);
while (x != x2) {
if (frac >= 0) {
y += stepy;
frac -= dx;
}
x += stepx;
frac += dy;
this->SetPixel(video, x, y, color);
}
} else {
frac = dx - (dy / 2);
while (y != y2) {
if (frac >= 0) {
x += stepx;
frac -= dy;
}
y += stepy;
frac += dx;
this->SetPixel(video, x, y, color);
}
}
}
void Blitter_8bppBase::CopyFromBuffer(void *video, const void *src, int width, int height, int src_pitch)
{
int direction = (height < 0) ? -1 : 1;
uint8 *dst = (uint8 *)video;
uint8 *usrc = (uint8 *)src;
height = abs(height);
for (; height > 0; height--) {
memcpy(dst, usrc, width);
usrc += src_pitch * direction;
dst += _screen.pitch * direction;
}
}
void Blitter_8bppBase::CopyToBuffer(const void *video, void *dst, int width, int height, int dst_pitch)
{
int direction = (height < 0) ? -1 : 1;
uint8 *udst = (uint8 *)dst;
uint8 *src = (uint8 *)video;
height = abs(height);
for (; height > 0; height--) {
memcpy(udst, src, width);
src += _screen.pitch * direction;
udst += dst_pitch * direction;
}
}
void Blitter_8bppBase::MoveBuffer(void *video_dst, const void *video_src, int width, int height)
{
uint8 *dst = (uint8 *)video_dst;
uint8 *src = (uint8 *)video_src;
for (; height > 0; height--) {
memmove(dst, src, width);
src += _screen.pitch;
dst += _screen.pitch;
}
}
int Blitter_8bppBase::BufferSize(int width, int height)
{
return width * height;
}

27
src/blitter/8bpp_base.hpp Normal file
View File

@@ -0,0 +1,27 @@
/* $Id$ */
/** @file 8bpp_base.hpp */
#ifndef BLITTER_8BPP_BASE_HPP
#define BLITTER_8BPP_BASE_HPP
#include "base.hpp"
class Blitter_8bppBase : public Blitter {
public:
/* virtual */ uint8 GetScreenDepth() { return 8; }
// /* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
/* virtual */ void DrawColorMappingRect(void *dst, int width, int height, int pal);
// /* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator);
/* virtual */ void *MoveTo(const void *video, int x, int y);
/* virtual */ void SetPixel(void *video, int x, int y, uint8 color);
/* virtual */ void SetPixelIfEmpty(void *video, int x, int y, uint8 color);
/* virtual */ void SetHorizontalLine(void *video, int width, uint8 color);
/* virtual */ void DrawLine(void *video, int x, int y, int x2, int y2, uint8 color);
/* virtual */ void CopyFromBuffer(void *video, const void *src, int width, int height, int src_pitch);
/* virtual */ void CopyToBuffer(const void *video, void *dst, int width, int height, int dst_pitch);
/* virtual */ void MoveBuffer(void *video_dst, const void *video_src, int width, int height);
/* virtual */ int BufferSize(int width, int height);
};
#endif /* BLITTER_8BPP_BASE_HPP */

View File

@@ -35,16 +35,6 @@ void Blitter_8bppDebug::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomL
}
}
void Blitter_8bppDebug::DrawColorMappingRect(void *dst, int width, int height, int pal)
{
const uint8 *ctab = GetNonSprite(pal) + 1;
do {
for (int i = 0; i != width; i++) _screen.renderer->SetPixel(dst, i, 0, ctab[((uint8 *)dst)[i]]);
dst = _screen.renderer->MoveTo(dst, 0, 1);
} while (height--);
}
Sprite *Blitter_8bppDebug::Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator)
{
Sprite *dest_sprite;

View File

@@ -5,27 +5,19 @@
#ifndef BLITTER_8BPP_DEBUG_HPP
#define BLITTER_8BPP_DEBUG_HPP
#include "blitter.hpp"
#include "8bpp_base.hpp"
#include "factory.hpp"
class Blitter_8bppDebug : public Blitter {
class Blitter_8bppDebug : public Blitter_8bppBase {
public:
/* virtual */ uint8 GetScreenDepth() { return 8; }
/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
/* virtual */ void DrawColorMappingRect(void *dst, int width, int height, int pal);
/* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator);
/* virtual */ const char *GetRenderer() { return "8bpp"; }
};
class FBlitter_8bppDebug: public BlitterFactory<FBlitter_8bppDebug> {
public:
/* virtual */ const char *GetName() { return "8bpp-debug"; }
/* virtual */ const char *GetDescription() { return "8bpp Debug Blitter (testing only)"; }
/* virtual */ Blitter *CreateInstance() { return new Blitter_8bppDebug(); }
};

View File

@@ -102,16 +102,6 @@ void Blitter_8bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Z
}
}
void Blitter_8bppOptimized::DrawColorMappingRect(void *dst, int width, int height, int pal)
{
const uint8 *ctab = GetNonSprite(pal) + 1;
do {
for (int i = 0; i != width; i++) _screen.renderer->SetPixel(dst, i, 0, ctab[((uint8 *)dst)[i]]);
dst = _screen.renderer->MoveTo(dst, 0, 1);
} while (height--);
}
Sprite *Blitter_8bppOptimized::Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator)
{
Sprite *dest_sprite;

View File

@@ -5,27 +5,19 @@
#ifndef BLITTER_8BPP_OPTIMIZED_HPP
#define BLITTER_8BPP_OPTIMIZED_HPP
#include "blitter.hpp"
#include "8bpp_base.hpp"
#include "factory.hpp"
class Blitter_8bppOptimized : public Blitter {
class Blitter_8bppOptimized : public Blitter_8bppBase {
public:
/* virtual */ uint8 GetScreenDepth() { return 8; }
/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
/* virtual */ void DrawColorMappingRect(void *dst, int width, int height, int pal);
/* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator);
/* virtual */ const char *GetRenderer() { return "8bpp"; }
};
class FBlitter_8bppOptimized: public BlitterFactory<FBlitter_8bppOptimized> {
public:
/* virtual */ const char *GetName() { return "8bpp-optimized"; }
/* virtual */ const char *GetDescription() { return "8bpp Optimized Blitter (compression + all-ZoomLevel cache)"; }
/* virtual */ Blitter *CreateInstance() { return new Blitter_8bppOptimized(); }
};

View File

@@ -48,16 +48,6 @@ void Blitter_8bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Zoom
}
}
void Blitter_8bppSimple::DrawColorMappingRect(void *dst, int width, int height, int pal)
{
const uint8 *ctab = GetNonSprite(pal) + 1;
do {
for (int i = 0; i != width; i++) _screen.renderer->SetPixel(dst, i, 0, ctab[((uint8 *)dst)[i]]);
dst = _screen.renderer->MoveTo(dst, 0, 1);
} while (height--);
}
Sprite *Blitter_8bppSimple::Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator)
{
Sprite *dest_sprite;

View File

@@ -5,27 +5,19 @@
#ifndef BLITTER_8BPP_SIMPLE_HPP
#define BLITTER_8BPP_SIMPLE_HPP
#include "blitter.hpp"
#include "8bpp_base.hpp"
#include "factory.hpp"
class Blitter_8bppSimple : public Blitter {
class Blitter_8bppSimple : public Blitter_8bppBase {
public:
/* virtual */ uint8 GetScreenDepth() { return 8; }
/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
/* virtual */ void DrawColorMappingRect(void *dst, int width, int height, int pal);
/* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator);
/* virtual */ const char *GetRenderer() { return "8bpp"; }
};
class FBlitter_8bppSimple: public BlitterFactory<FBlitter_8bppSimple> {
public:
/* virtual */ const char *GetName() { return "8bpp-simple"; }
/* virtual */ const char *GetDescription() { return "8bpp Simple Blitter (relative slow, but never wrong)"; }
/* virtual */ Blitter *CreateInstance() { return new Blitter_8bppSimple(); }
};

144
src/blitter/base.hpp Normal file
View File

@@ -0,0 +1,144 @@
/* $Id$ */
#ifndef BLITTER_BASE_HPP
#define BLITTER_BASE_HPP
#include "../spritecache.h"
#include "../spriteloader/spriteloader.hpp"
enum BlitterMode {
BM_NORMAL,
BM_COLOUR_REMAP,
BM_TRANSPARENT,
};
/**
* How all blitters should look like. Extend this class to make your own.
*/
class Blitter {
public:
struct BlitterParams {
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
void *dst; ///< Destination buffer
int pitch; ///< The pitch of the destination buffer
};
typedef void *AllocatorProc(size_t size);
/**
* Get the screen depth this blitter works for.
* This is either: 8, 16, 24 or 32.
*/
virtual uint8 GetScreenDepth() = 0;
/**
* Draw an image to the screen, given an amount of params defined above.
*/
virtual void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) = 0;
/**
* Draw a colortable to the screen. This is: the color of the screen is read
* and is looked-up in the palette to match a new color, which then is put
* on the screen again.
* @param dst the destination pointer (video-buffer).
* @param width the width of the buffer.
* @param height the height of the buffer.
* @param pal the palette to use.
*/
virtual void DrawColorMappingRect(void *dst, int width, int height, int pal) = 0;
/**
* Convert a sprite from the loader to our own format.
*/
virtual Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator) = 0;
/**
* Move the destination pointer the requested amount x and y, keeping in mind
* any pitch and bpp of the renderer.
* @param video The destination pointer (video-buffer) to scroll.
* @param x How much you want to scroll to the right.
* @param y How much you want to scroll to the bottom.
* @return A new destination pointer moved the the requested place.
*/
virtual void *MoveTo(const void *video, int x, int y) = 0;
/**
* Draw a pixel with a given color on the video-buffer.
* @param video The destination pointer (video-buffer).
* @param x The x position within video-buffer.
* @param y The y position within video-buffer.
* @param color A 8bpp mapping color.
*/
virtual void SetPixel(void *video, int x, int y, uint8 color) = 0;
/**
* Draw a pixel with a given color on the video-buffer if there is currently a black pixel.
* @param video The destination pointer (video-buffer).
* @param x The x position within video-buffer.
* @param y The y position within video-buffer.
* @param color A 8bpp mapping color.
*/
virtual void SetPixelIfEmpty(void *video, int x, int y, uint8 color) = 0;
/**
* Make a single horizontal line in a single color on the video-buffer.
* @param video The destination pointer (video-buffer).
* @param width The lenght of the line.
* @param color A 8bpp mapping color.
*/
virtual void SetHorizontalLine(void *video, int width, uint8 color) = 0;
/**
* Draw a line in which ever direction.
*/
virtual void DrawLine(void *video, int x, int y, int x2, int y2, uint8 color) = 0;
/**
* Copy from a buffer to the screen.
* @param video The destionation pointer (video-buffer).
* @param src The buffer from which the data will be read.
* @param width The width of the buffer.
* @param height The height of the buffer.
* @param src_pitch The pitch (byte per line) of the source buffer.
*/
virtual void CopyFromBuffer(void *video, const void *src, int width, int height, int src_pitch) = 0;
/**
* Copy from the screen to a buffer.
* @param video The destination pointer (video-buffer).
* @param dst The buffer in which the data will be stored.
* @param width The width of the buffer.
* @param height The height of the buffer.
* @param dst_pitch The pitch (byte per line) of the destination buffer.
*/
virtual void CopyToBuffer(const void *video, void *dst, int width, int height, int dst_pitch) = 0;
/**
* Move the videobuffer some places (via memmove).
* @param video_dst The destination pointer (video-buffer).
* @param video_src The source pointer (video-buffer).
* @param width The width of the buffer to move.
* @param height The height of the buffer to move.
*/
virtual void MoveBuffer(void *video_dst, const void *video_src, int width, int height) = 0;
/**
* Calculate how much memory there is needed for an image of this size in the video-buffer.
* @param width The width of the buffer-to-be.
* @param height The height of the buffer-to-be.
* @return The size needed for the buffer.
*/
virtual int BufferSize(int width, int height) = 0;
virtual ~Blitter() { }
};
#endif /* BLITTER_BASE_HPP */

View File

@@ -1,77 +1,12 @@
/* $Id$ */
/** @file blitter.hpp */
#ifndef BLITTER_FACTORY_HPP
#define BLITTER_FACTORY_HPP
#ifndef BLITTER_HPP
#define BLITTER_HPP
#include "../spriteloader/spriteloader.hpp"
#include "../spritecache.h"
#include "base.hpp"
#include <string>
#include <map>
enum BlitterMode {
BM_NORMAL,
BM_COLOUR_REMAP,
BM_TRANSPARENT,
};
/**
* How all blitters should look like. Extend this class to make your own.
*/
class Blitter {
public:
struct BlitterParams {
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
void *dst; ///< Destination buffer
int pitch; ///< The pitch of the destination buffer
};
typedef void *AllocatorProc(size_t size);
/**
* Get the screen depth this blitter works for.
* This is either: 8, 16, 24 or 32.
*/
virtual uint8 GetScreenDepth() = 0;
/**
* Draw an image to the screen, given an amount of params defined above.
*/
virtual void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) = 0;
/**
* Draw a colortable to the screen. This is: the color of the screen is read
* and is looked-up in the palette to match a new color, which then is put
* on the screen again.
* @param dst the destination pointer (video-buffer).
* @param width the width of the buffer.
* @param height the height of the buffer.
* @param pal the palette to use.
*/
virtual void DrawColorMappingRect(void *dst, int width, int height, int pal) = 0;
/**
* Convert a sprite from the loader to our own format.
*/
virtual Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator) = 0;
/**
* Get the renderer this class depends on.
*/
virtual const char *GetRenderer() = 0;
virtual ~Blitter() { }
};
/**
* The base factory, keeping track of all blitters.
*/
@@ -183,4 +118,4 @@ public:
const char *GetName();
};
#endif /* BLITTER_HPP */
#endif /* BLITTER_FACTORY_HPP */

View File

@@ -1,19 +1,9 @@
#include "../stdafx.h"
#include "../zoom.hpp"
#include "../gfx.h"
#include "../functions.h"
#include "../variables.h"
#include "null.hpp"
static FBlitter_Null iFBlitter_Null;
void Blitter_Null::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
{
}
void Blitter_Null::DrawColorMappingRect(void *dst, int width, int height, int pal)
{
}
Sprite *Blitter_Null::Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator)
{
Sprite *dest_sprite;

View File

@@ -5,27 +5,30 @@
#ifndef BLITTER_NULL_HPP
#define BLITTER_NULL_HPP
#include "blitter.hpp"
#include "base.hpp"
#include "factory.hpp"
class Blitter_Null : public Blitter {
public:
/* virtual */ uint8 GetScreenDepth() { return 0; }
/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
/* virtual */ void DrawColorMappingRect(void *dst, int width, int height, int pal);
/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) {};
/* virtual */ void DrawColorMappingRect(void *dst, int width, int height, int pal) {};
/* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator);
/* virtual */ const char *GetRenderer() { return "null"; }
/* virtual */ void *MoveTo(const void *video, int x, int y) { return NULL; };
/* virtual */ void SetPixel(void *video, int x, int y, uint8 color) {};
/* virtual */ void SetPixelIfEmpty(void *video, int x, int y, uint8 color) {};
/* virtual */ void SetHorizontalLine(void *video, int width, uint8 color) {};
/* virtual */ void DrawLine(void *video, int x, int y, int x2, int y2, uint8 color) {};
/* virtual */ void CopyFromBuffer(void *video, const void *src, int width, int height, int src_pitch) {};
/* virtual */ void CopyToBuffer(const void *video, void *dst, int width, int height, int dst_pitch) {};
/* virtual */ void MoveBuffer(void *video_dst, const void *video_src, int width, int height) {};
/* virtual */ int BufferSize(int width, int height) { return 0; };
};
class FBlitter_Null: public BlitterFactory<FBlitter_Null> {
public:
/* virtual */ const char *GetName() { return "null"; }
/* virtual */ const char *GetDescription() { return "Null Blitter (does nothing)"; }
/* virtual */ Blitter *CreateInstance() { return new Blitter_Null(); }
};