(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
pull/155/head
truelight 17 years ago
parent 8c3e9d111f
commit 79cd3f5db0

@ -40,7 +40,7 @@ file_prefix="..\\\\src\\\\"
safety_check() {
li=""
for i in `cat $1 | grep -v "#" | xargs -n 1 basename | sort`; do
for i in `cat $1 | grep -v "#\|ottdres.rc\|win32.cpp\|win32_v.cpp" | xargs -n 1 basename | sort`; do
if [ "$li" = "$i" ]; then
echo " !! ERROR !!"
echo ""

@ -967,12 +967,24 @@
<Filter
Name="Blitters"
Filter="">
<File
RelativePath=".\..\src\blitter\32bpp_base.cpp">
</File>
<File
RelativePath=".\..\src\blitter\32bpp_base.hpp">
</File>
<File
RelativePath=".\..\src\blitter\32bpp_simple.cpp">
</File>
<File
RelativePath=".\..\src\blitter\32bpp_simple.hpp">
</File>
<File
RelativePath=".\..\src\blitter\8bpp_base.cpp">
</File>
<File
RelativePath=".\..\src\blitter\8bpp_base.hpp">
</File>
<File
RelativePath=".\..\src\blitter\8bpp_debug.cpp">
</File>
@ -992,7 +1004,10 @@
RelativePath=".\..\src\blitter\8bpp_simple.hpp">
</File>
<File
RelativePath=".\..\src\blitter\blitter.hpp">
RelativePath=".\..\src\blitter\base.hpp">
</File>
<File
RelativePath=".\..\src\blitter\factory.hpp">
</File>
<File
RelativePath=".\..\src\blitter\null.cpp">
@ -1020,31 +1035,6 @@
RelativePath=".\..\src\spriteloader\spriteloader.hpp">
</File>
</Filter>
<Filter
Name="Renderer"
Filter="">
<File
RelativePath=".\..\src\renderer\32bpp.cpp">
</File>
<File
RelativePath=".\..\src\renderer\32bpp.hpp">
</File>
<File
RelativePath=".\..\src\renderer\8bpp.cpp">
</File>
<File
RelativePath=".\..\src\renderer\8bpp.hpp">
</File>
<File
RelativePath=".\..\src\renderer\null.cpp">
</File>
<File
RelativePath=".\..\src\renderer\null.hpp">
</File>
<File
RelativePath=".\..\src\renderer\renderer.hpp">
</File>
</Filter>
<Filter
Name="NewGRF"
Filter="">

@ -1511,6 +1511,14 @@
<Filter
Name="Blitters"
>
<File
RelativePath=".\..\src\blitter\32bpp_base.cpp"
>
</File>
<File
RelativePath=".\..\src\blitter\32bpp_base.hpp"
>
</File>
<File
RelativePath=".\..\src\blitter\32bpp_simple.cpp"
>
@ -1519,6 +1527,14 @@
RelativePath=".\..\src\blitter\32bpp_simple.hpp"
>
</File>
<File
RelativePath=".\..\src\blitter\8bpp_base.cpp"
>
</File>
<File
RelativePath=".\..\src\blitter\8bpp_base.hpp"
>
</File>
<File
RelativePath=".\..\src\blitter\8bpp_debug.cpp"
>
@ -1544,7 +1560,11 @@
>
</File>
<File
RelativePath=".\..\src\blitter\blitter.hpp"
RelativePath=".\..\src\blitter\base.hpp"
>
</File>
<File
RelativePath=".\..\src\blitter\factory.hpp"
>
</File>
<File
@ -1580,38 +1600,6 @@
>
</File>
</Filter>
<Filter
Name="Renderer"
>
<File
RelativePath=".\..\src\renderer\32bpp.cpp"
>
</File>
<File
RelativePath=".\..\src\renderer\32bpp.hpp"
>
</File>
<File
RelativePath=".\..\src\renderer\8bpp.cpp"
>
</File>
<File
RelativePath=".\..\src\renderer\8bpp.hpp"
>
</File>
<File
RelativePath=".\..\src\renderer\null.cpp"
>
</File>
<File
RelativePath=".\..\src\renderer\null.hpp"
>
</File>
<File
RelativePath=".\..\src\renderer\renderer.hpp"
>
</File>
</Filter>
<Filter
Name="NewGRF"
>

@ -293,15 +293,20 @@ ai/trolly/shared.cpp
ai/trolly/trolly.cpp
# Blitters
blitter/32bpp_base.cpp
blitter/32bpp_base.hpp
blitter/32bpp_simple.cpp
blitter/32bpp_simple.hpp
blitter/8bpp_base.cpp
blitter/8bpp_base.hpp
blitter/8bpp_debug.cpp
blitter/8bpp_debug.hpp
blitter/8bpp_optimized.cpp
blitter/8bpp_optimized.hpp
blitter/8bpp_simple.cpp
blitter/8bpp_simple.hpp
blitter/blitter.hpp
blitter/base.hpp
blitter/factory.hpp
blitter/null.cpp
blitter/null.hpp
@ -314,15 +319,6 @@ spriteloader/png.hpp
#end
spriteloader/spriteloader.hpp
# Renderer
renderer/32bpp.cpp
renderer/32bpp.hpp
renderer/8bpp.cpp
renderer/8bpp.hpp
renderer/null.cpp
renderer/null.hpp
renderer/renderer.hpp
# NewGRF
newgrf.cpp
newgrf_canal.cpp

@ -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);
}

@ -1,18 +1,23 @@
/* $Id$ */
/** @file 32bpp.hpp */
/** @file 32bpp_base.hpp */
#ifndef RENDERER_32BPP_HPP
#define RENDERER_32BPP_HPP
#ifndef BLITTER_32BPP_BASE_HPP
#define BLITTER_32BPP_BASE_HPP
#include "renderer.hpp"
#include "base.hpp"
class Renderer_32bpp : public Renderer {
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);
@ -25,11 +30,4 @@ public:
}
};
class FRenderer_32bpp: public RendererFactory<FRenderer_32bpp> {
public:
/* virtual */ const char *GetName() { return "32bpp"; }
/* virtual */ Renderer *CreateInstance() { return new Renderer_32bpp(); }
};
#endif /* RENDERER_32BPP_HPP */
#endif /* BLITTER_32BPP_BASE_HPP */

@ -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);

@ -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(); }
};

@ -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;
}

@ -1,29 +1,27 @@
/* $Id$ */
/** @file 8bpp.hpp */
/** @file 8bpp_base.hpp */
#ifndef RENDERER_8BPP_HPP
#define RENDERER_8BPP_HPP
#ifndef BLITTER_8BPP_BASE_HPP
#define BLITTER_8BPP_BASE_HPP
#include "renderer.hpp"
#include "base.hpp"
class Renderer_8bpp : public Renderer {
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);
};
class FRenderer_8bpp: public RendererFactory<FRenderer_8bpp> {
public:
/* virtual */ const char *GetName() { return "8bpp"; }
/* virtual */ Renderer *CreateInstance() { return new Renderer_8bpp(); }
};
#endif /* RENDERER_8BPP_HPP */
#endif /* BLITTER_8BPP_BASE_HPP */

@ -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;

@ -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(); }
};

@ -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;

@ -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(); }
};

@ -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;

@ -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(); }
};

@ -1,16 +1,64 @@
/* $Id$ */
/** @file renderer.hpp */
#ifndef BLITTER_BASE_HPP
#define BLITTER_BASE_HPP
#ifndef RENDERER_HPP
#define RENDERER_HPP
#include "../spritecache.h"
#include "../spriteloader/spriteloader.hpp"
#include <string>
#include <map>
enum BlitterMode {
BM_NORMAL,
BM_COLOUR_REMAP,
BM_TRANSPARENT,
};
class Renderer {
/**
* How all blitters should look like. Extend this class to make your own.
*/
class Blitter {
public:
virtual ~Renderer() { }
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
@ -48,6 +96,11 @@ public:
*/
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).
@ -84,82 +137,8 @@ public:
* @return The size needed for the buffer.
*/
virtual int BufferSize(int width, int height) = 0;
};
/**
* The factory, keeping track of all renderers.
*/
class RendererFactoryBase {
private:
char *name;
typedef std::map<std::string, RendererFactoryBase *> Renderers;
static Renderers &GetRenderers()
{
static Renderers &s_renderers = *new Renderers();
return s_renderers;
}
protected:
/**
* Register a renderer internally, based on his bpp.
* @param name the name of the renderer.
* @note an assert() will be trigger if 2 renderers with the same bpp try to register.
*/
void RegisterRenderer(const char *name)
{
/* Don't register nameless Renderers */
if (name == NULL) return;
this->name = strdup(name);
std::pair<Renderers::iterator, bool> P = GetRenderers().insert(Renderers::value_type(name, this));
assert(P.second);
}
public:
RendererFactoryBase() :
name(NULL)
{ }
virtual ~RendererFactoryBase() { if (this->name != NULL) GetRenderers().erase(this->name); free(this->name); }
/**
* Find the requested renderer and return his class-instance.
* @param name the renderer to select.
*/
static Renderer *SelectRenderer(const char *name)
{
if (GetRenderers().size() == 0) return NULL;
Renderers::iterator it = GetRenderers().begin();
for (; it != GetRenderers().end(); it++) {
RendererFactoryBase *r = (*it).second;
if (strcasecmp(name, r->name) == 0) {
return r->CreateInstance();
}
}
return NULL;
}
/**
* Create an instance of this Renderer-class.
*/
virtual Renderer *CreateInstance() = 0;
virtual ~Blitter() { }
};
/**
* A template factory, so ->GetBpp() works correctly. This because else some compiler will complain.
*/
template <class T>
class RendererFactory: public RendererFactoryBase {
public:
RendererFactory() { this->RegisterRenderer(((T *)this)->GetName()); }
/**
* Get the name for this renderer.
*/
const char *GetName();
};
#endif /* RENDERER_HPP */
#endif /* BLITTER_BASE_HPP */

@ -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 */

@ -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;

@ -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(); }
};

@ -15,7 +15,7 @@
#include "fontcache.h"
#include "helpers.hpp"
#include "spriteloader/spriteloader.hpp"
#include "blitter/blitter.hpp"
#include "blitter/factory.hpp"
#ifdef WITH_FREETYPE

@ -19,7 +19,7 @@
#include "genworld.h"
#include "debug.h"
#include "zoom.hpp"
#include "blitter/blitter.hpp"
#include "blitter/factory.hpp"
#ifdef _DEBUG
bool _dbg_screen_rect;
@ -60,6 +60,7 @@ static byte _dirty_blocks[DIRTY_BYTES_PER_LINE * MAX_SCREEN_HEIGHT / 8];
void GfxScroll(int left, int top, int width, int height, int xo, int yo)
{
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
const void *src;
void *dst;
@ -70,8 +71,8 @@ void GfxScroll(int left, int top, int width, int height, int xo, int yo)
if (yo > 0) {
/*Calculate pointers */
dst = _screen.renderer->MoveTo(_screen.dst_ptr, left, top + height - 1);
src = _screen.renderer->MoveTo(dst, 0, -yo);
dst = blitter->MoveTo(_screen.dst_ptr, left, top + height - 1);
src = blitter->MoveTo(dst, 0, -yo);
/* Decrease height and increase top */
top += yo;
@ -80,20 +81,20 @@ void GfxScroll(int left, int top, int width, int height, int xo, int yo)
/* Adjust left & width */
if (xo >= 0) {
dst = _screen.renderer->MoveTo(dst, xo, 0);
dst = blitter->MoveTo(dst, xo, 0);
left += xo;
width -= xo;
} else {
src = _screen.renderer->MoveTo(src, -xo, 0);
src = blitter->MoveTo(src, -xo, 0);
width += xo;
}
/* Negative height as we want to copy from bottom to top */
_screen.renderer->CopyFromBuffer(dst, src, width, -height, _screen.pitch);
blitter->CopyFromBuffer(dst, src, width, -height, _screen.pitch);
} else {
/* Calculate pointers */
dst = _screen.renderer->MoveTo(_screen.dst_ptr, left, top);
src = _screen.renderer->MoveTo(dst, 0, -yo);
dst = blitter->MoveTo(_screen.dst_ptr, left, top);
src = blitter->MoveTo(dst, 0, -yo);
/* Decrese height. (yo is <=0). */
height += yo;
@ -101,17 +102,17 @@ void GfxScroll(int left, int top, int width, int height, int xo, int yo)
/* Adjust left & width */
if (xo >= 0) {
dst = _screen.renderer->MoveTo(dst, xo, 0);
dst = blitter->MoveTo(dst, xo, 0);
left += xo;
width -= xo;
} else {
src = _screen.renderer->MoveTo(src, -xo, 0);
src = blitter->MoveTo(src, -xo, 0);
width += xo;
}
/* the y-displacement may be 0 therefore we have to use memmove,
* because source and destination may overlap */
_screen.renderer->MoveBuffer(dst, src, width, height);
blitter->MoveBuffer(dst, src, width, height);
}
/* This part of the screen is now dirty. */
_video_driver->make_dirty(left, top, width, height);
@ -120,6 +121,7 @@ void GfxScroll(int left, int top, int width, int height, int xo, int yo)
void GfxFillRect(int left, int top, int right, int bottom, int color)
{
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
const DrawPixelInfo *dpi = _cur_dpi;
void *dst;
const int otop = top;
@ -142,31 +144,33 @@ void GfxFillRect(int left, int top, int right, int bottom, int color)
bottom -= top;
assert(bottom > 0);
dst = _screen.renderer->MoveTo(dpi->dst_ptr, left, top);
dst = blitter->MoveTo(dpi->dst_ptr, left, top);
if (!HASBIT(color, PALETTE_MODIFIER_GREYOUT)) {
if (!HASBIT(color, USE_COLORTABLE)) {
do {
_screen.renderer->SetHorizontalLine(dst, right, (uint8)color);
dst = _screen.renderer->MoveTo(dst, 0, 1);
blitter->SetHorizontalLine(dst, right, (uint8)color);
dst = blitter->MoveTo(dst, 0, 1);
} while (--bottom);
} else {
BlitterFactoryBase::GetCurrentBlitter()->DrawColorMappingRect(dst, right, bottom, GB(color, 0, PALETTE_WIDTH));
blitter->DrawColorMappingRect(dst, right, bottom, GB(color, 0, PALETTE_WIDTH));
}
} else {
byte bo = (oleft - left + dpi->left + otop - top + dpi->top) & 1;
do {
for (int i = (bo ^= 1); i < right; i += 2) _screen.renderer->SetPixel(dst, i, 0, (uint8)color);
dst = _screen.renderer->MoveTo(dst, 0, 1);
for (int i = (bo ^= 1); i < right; i += 2) blitter->SetPixel(dst, i, 0, (uint8)color);
dst = blitter->MoveTo(dst, 0, 1);
} while (--bottom > 0);
}
}
static void GfxSetPixel(int x, int y, int color)
{
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
const DrawPixelInfo *dpi = _cur_dpi;
if ((x -= dpi->left) < 0 || x >= dpi->width || (y -= dpi->top) < 0 || y >= dpi->height) return;
_screen.renderer->SetPixel(dpi->dst_ptr, x, y, color);
blitter->SetPixel(dpi->dst_ptr, x, y, color);
}
void GfxDrawLine(int x, int y, int x2, int y2, int color)
@ -934,14 +938,16 @@ void ScreenSizeChanged()
void UndrawMouseCursor()
{
if (_cursor.visible) {
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
_cursor.visible = false;
_screen.renderer->CopyFromBuffer(_screen.renderer->MoveTo(_screen.dst_ptr, _cursor.draw_pos.x, _cursor.draw_pos.y), _cursor_backup, _cursor.draw_size.x, _cursor.draw_size.y, _cursor.draw_size.x);
blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, _cursor.draw_pos.x, _cursor.draw_pos.y), _cursor_backup, _cursor.draw_size.x, _cursor.draw_size.y, _cursor.draw_size.x);
_video_driver->make_dirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y);
}
}
void DrawMouseCursor()
{
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
int x;
int y;
int w;
@ -978,10 +984,10 @@ void DrawMouseCursor()
_cursor.draw_pos.y = y;
_cursor.draw_size.y = h;
assert(_screen.renderer->BufferSize(w, h) < (int)sizeof(_cursor_backup));
assert(blitter->BufferSize(w, h) < (int)sizeof(_cursor_backup));
/* Make backup of stuff below cursor */
_screen.renderer->CopyToBuffer(_screen.renderer->MoveTo(_screen.dst_ptr, _cursor.draw_pos.x, _cursor.draw_pos.y), _cursor_backup, _cursor.draw_size.x, _cursor.draw_size.y, _cursor.draw_size.x);
blitter->CopyToBuffer(blitter->MoveTo(_screen.dst_ptr, _cursor.draw_pos.x, _cursor.draw_pos.y), _cursor_backup, _cursor.draw_size.x, _cursor.draw_size.y, _cursor.draw_size.x);
/* Draw cursor on screen */
_cur_dpi = &_screen;
@ -1171,6 +1177,7 @@ void MarkWholeScreenDirty()
* get some nasty results */
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
{
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
const DrawPixelInfo *o = _cur_dpi;
n->zoom = ZOOM_LVL_NORMAL;
@ -1202,7 +1209,7 @@ bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int heigh
n->top = 0;
}
n->dst_ptr = _screen.renderer->MoveTo(o->dst_ptr, left, top);
n->dst_ptr = blitter->MoveTo(o->dst_ptr, left, top);
n->pitch = o->pitch;
if (height > o->height - top) {

@ -7,7 +7,6 @@
#include "openttd.h"
#include "zoom.hpp"
#include "renderer/renderer.hpp"
enum WindowKeyCodes {
WKC_SHIFT = 0x8000,
@ -138,7 +137,6 @@ struct DrawPixelInfo {
int left, top, width, height;
int pitch;
ZoomLevel zoom;
Renderer *renderer;
};
struct Colour {

@ -64,7 +64,7 @@
#include "newgrf_commons.h"
#include "player_face.h"
#include "group.h"
#include "blitter/blitter.hpp"
#include "blitter/factory.hpp"
#include "bridge_map.h"
#include "clear_map.h"

@ -1,77 +0,0 @@
#include "../stdafx.h"
#include "../gfx.h"
#include "32bpp.hpp"
static FRenderer_32bpp iFRenderer_32bpp;
void *Renderer_32bpp::MoveTo(const void *video, int x, int y)
{
return (uint32 *)video + x + y * _screen.pitch;
}
void Renderer_32bpp::SetPixel(void *video, int x, int y, uint8 color)
{
*((uint32 *)video + x + y * _screen.pitch) = LookupColourInPalette(color);
}
void Renderer_32bpp::SetPixelIfEmpty(void *video, int x, int y, uint8 color)
{
uint32 *dst = (uint32 *)video + x + y * _screen.pitch;
if (*dst == 0) *dst = LookupColourInPalette(color);
}
void Renderer_32bpp::SetHorizontalLine(void *video, int width, uint8 color)
{
uint32 *dst = (uint32 *)video;
uint32 color32 = LookupColourInPalette(color);
for (; width > 0; width--) {
*dst = color32;
dst++;
}
}
void Renderer_32bpp::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 Renderer_32bpp::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 Renderer_32bpp::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 Renderer_32bpp::BufferSize(int width, int height)
{
return width * height * sizeof(uint32);
}

@ -1,71 +0,0 @@
#include "../stdafx.h"
#include "../gfx.h"
#include "8bpp.hpp"
static FRenderer_8bpp iFRenderer_8bpp;
void *Renderer_8bpp::MoveTo(const void *video, int x, int y)
{
return (uint8 *)video + x + y * _screen.pitch;
}
void Renderer_8bpp::SetPixel(void *video, int x, int y, uint8 color)
{
*((uint8 *)video + x + y * _screen.pitch) = color;
}
void Renderer_8bpp::SetPixelIfEmpty(void *video, int x, int y, uint8 color)
{
uint8 *dst = (uint8 *)video + x + y * _screen.pitch;
if (*dst == 0) *dst = color;
}
void Renderer_8bpp::SetHorizontalLine(void *video, int width, uint8 color)
{
memset(video, color, width);
}
void Renderer_8bpp::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 Renderer_8bpp::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 Renderer_8bpp::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 Renderer_8bpp::BufferSize(int width, int height)
{
return width * height;
}

@ -1,39 +0,0 @@
#include "../stdafx.h"
#include "../gfx.h"
#include "null.hpp"
static FRenderer_Null iFRenderer_Null;
void *Renderer_Null::MoveTo(const void *video, int x, int y)
{
return NULL;
}
void Renderer_Null::SetPixel(void *video, int x, int y, uint8 color)
{
}
void Renderer_Null::SetPixelIfEmpty(void *video, int x, int y, uint8 color)
{
}
void Renderer_Null::SetHorizontalLine(void *video, int width, uint8 color)
{
}
void Renderer_Null::CopyFromBuffer(void *video, const void *src, int width, int height, int src_pitch)
{
}
void Renderer_Null::CopyToBuffer(const void *video, void *dst, int width, int height, int dst_pitch)
{
}
void Renderer_Null::MoveBuffer(void *video_dst, const void *video_src, int width, int height)
{
}
int Renderer_Null::BufferSize(int width, int height)
{
return 0;
}

@ -1,29 +0,0 @@
/* $Id$ */
/** @file null.hpp */
#ifndef RENDERER_NULL_HPP
#define RENDERER_NULL_HPP
#include "renderer.hpp"
class Renderer_Null : public Renderer {
public:
/* 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 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);
};
class FRenderer_Null: public RendererFactory<FRenderer_Null> {
public:
/* virtual */ const char *GetName() { return "null"; }
/* virtual */ Renderer *CreateInstance() { return new Renderer_Null(); }
};
#endif /* RENDERER_NULL_HPP */

@ -16,7 +16,7 @@
#include "date.h"
#include "string.h"
#include "helpers.hpp"
#include "blitter/blitter.hpp"
#include "blitter/factory.hpp"
#include "fileio.h"
char _screenshot_format_name[8];
@ -483,8 +483,9 @@ void SetScreenshotFormat(int i)
/* screenshot generator that dumps the current video buffer */
static void CurrentScreenCallback(void *userdata, void *buf, uint y, uint pitch, uint n)
{
void *src = _screen.renderer->MoveTo(_screen.dst_ptr, 0, y);
_screen.renderer->CopyToBuffer(src, buf, _screen.width, n, pitch);
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
void *src = blitter->MoveTo(_screen.dst_ptr, 0, y);
blitter->CopyToBuffer(src, buf, _screen.width, n, pitch);
}
/* generate a large piece of the world */

@ -25,6 +25,7 @@
#include "town.h"
#include "sound.h"
#include "variables.h"
#include "blitter/factory.hpp"
static const Widget _smallmap_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
@ -169,20 +170,24 @@ static const LegendAndColour * const _legend_table[] = {
static inline void WRITE_PIXELS(void *d, uint32 val)
{
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
uint8 *val8 = (uint8 *)&val;
_screen.renderer->SetPixel(d, 0, 0, val8[0]);
_screen.renderer->SetPixel(d, 1, 0, val8[1]);
_screen.renderer->SetPixel(d, 2, 0, val8[2]);
_screen.renderer->SetPixel(d, 3, 0, val8[3]);
blitter->SetPixel(d, 0, 0, val8[0]);
blitter->SetPixel(d, 1, 0, val8[1]);
blitter->SetPixel(d, 2, 0, val8[2]);
blitter->SetPixel(d, 3, 0, val8[3]);
}
static inline void WRITE_PIXELS_OR(void *d, uint32 val)
{
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
uint8 *val8 = (uint8 *)&val;
_screen.renderer->SetPixelIfEmpty(d, 0, 0, val8[0]);
_screen.renderer->SetPixelIfEmpty(d, 1, 0, val8[1]);
_screen.renderer->SetPixelIfEmpty(d, 2, 0, val8[2]);
_screen.renderer->SetPixelIfEmpty(d, 3, 0, val8[3]);
blitter->SetPixelIfEmpty(d, 0, 0, val8[0]);
blitter->SetPixelIfEmpty(d, 1, 0, val8[1]);
blitter->SetPixelIfEmpty(d, 2, 0, val8[2]);
blitter->SetPixelIfEmpty(d, 3, 0, val8[3]);
}
#define MKCOLOR(x) TO_LE32X(x)
@ -280,7 +285,8 @@ typedef uint32 GetSmallMapPixels(TileIndex tile); // typedef callthrough functio
*/
static void DrawSmallMapStuff(void *dst, uint xc, uint yc, int pitch, int reps, uint32 mask, GetSmallMapPixels *proc)
{
void *dst_ptr_end = _screen.renderer->MoveTo(_screen.dst_ptr, _screen.width, _screen.height - 1);
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
void *dst_ptr_end = blitter->MoveTo(_screen.dst_ptr, _screen.width, _screen.height - 1);
do {
/* check if the tile (xc,yc) is within the map range */
@ -290,7 +296,7 @@ static void DrawSmallMapStuff(void *dst, uint xc, uint yc, int pitch, int reps,
WRITE_PIXELS_OR(dst, proc(TileXY(xc, yc)) & mask);
}
/* switch to next tile in the column */
} while (xc++, yc++, dst = _screen.renderer->MoveTo(dst, pitch, 0), --reps != 0);
} while (xc++, yc++, dst = blitter->MoveTo(dst, pitch, 0), --reps != 0);
}
@ -510,6 +516,7 @@ static void DrawHorizMapIndicator(int x, int y, int x2, int y2)
*/
static void DrawSmallMap(DrawPixelInfo *dpi, Window *w, int type, bool show_towns)
{
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
DrawPixelInfo *old_dpi;
int dx,dy, x, y, x2, y2;
void *ptr;
@ -564,7 +571,7 @@ static void DrawSmallMap(DrawPixelInfo *dpi, Window *w, int type, bool show_town
}
}
ptr = _screen.renderer->MoveTo(dpi->dst_ptr, -dx - 4, 0);
ptr = blitter->MoveTo(dpi->dst_ptr, -dx - 4, 0);
x = - dx - 4;
y = 0;
@ -598,13 +605,13 @@ skip_column:
if (y == 0) {
tile_y++;
y++;
ptr = _screen.renderer->MoveTo(ptr, 0, 1);
ptr = blitter->MoveTo(ptr, 0, 1);
} else {
tile_x--;
y--;
ptr = _screen.renderer->MoveTo(ptr, 0, -1);
ptr = blitter->MoveTo(ptr, 0, -1);
}
ptr = _screen.renderer->MoveTo(ptr, 2, 0);
ptr = blitter->MoveTo(ptr, 2, 0);
x += 2;
}
@ -650,8 +657,8 @@ skip_column:
color = (type == 1) ? _vehicle_type_colors[v->type] : 0xF;
/* And draw either one or two pixels depending on clipping */
_screen.renderer->SetPixel(dpi->dst_ptr, x, y, color);
if (!skip) _screen.renderer->SetPixel(dpi->dst_ptr, x + 1, y, color);;
blitter->SetPixel(dpi->dst_ptr, x, y, color);
if (!skip) blitter->SetPixel(dpi->dst_ptr, x + 1, y, color);
}
}
}

@ -17,7 +17,7 @@
#ifdef WITH_PNG
#include "spriteloader/png.hpp"
#endif /* WITH_PNG */
#include "blitter/blitter.hpp"
#include "blitter/factory.hpp"
/* Default of 4MB spritecache */
uint _sprite_cache_size = 4;

@ -16,6 +16,7 @@
#include "string.h"
#include "variables.h"
#include "table/sprites.h"
#include "blitter/factory.hpp"
#include <stdarg.h> /* va_list */
#include "date.h"
@ -126,6 +127,7 @@ void InitTextMessage()
void UndrawTextMessage()
{
if (_textmessage_visible) {
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
/* Sometimes we also need to hide the cursor
* This is because both textmessage and the cursor take a shot of the
* screen before drawing.
@ -161,7 +163,7 @@ void UndrawTextMessage()
_textmessage_visible = false;
/* Put our 'shot' back to the screen */
_screen.renderer->CopyFromBuffer(_screen.renderer->MoveTo(_screen.dst_ptr, x, y), _textmessage_backup, width, height, _textmsg_box.width);
blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), _textmessage_backup, width, height, _textmsg_box.width);
/* And make sure it is updated next time */
_video_driver->make_dirty(x, y, width, height);
@ -196,6 +198,7 @@ void TextMessageDailyLoop()
/** Draw the textmessage-box */
void DrawTextMessage()
{
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
if (!_textmessage_dirty) return;
/* First undraw if needed */
@ -221,7 +224,7 @@ void DrawTextMessage()
if (width <= 0 || height <= 0) return;
/* Make a copy of the screen as it is before painting (for undraw) */
_screen.renderer->CopyToBuffer(_screen.renderer->MoveTo(_screen.dst_ptr, x, y), _textmessage_backup, width, height, _textmsg_box.width);
blitter->CopyToBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), _textmessage_backup, width, height, _textmsg_box.width);
_cur_dpi = &_screen; // switch to _screen painting

@ -1763,9 +1763,6 @@ static void QZ_VideoInit()
_cocoa_video_data.cursor_visible = true;
_screen.renderer = RendererFactoryBase::SelectRenderer(BlitterFactoryBase::GetCurrentBlitter()->GetRenderer());
if (_screen.renderer == NULL) error("Couldn't load the renderer '%s' the selected blitter depends on", BlitterFactoryBase::GetCurrentBlitter()->GetRenderer());
/* register for sleep notifications so wake from sleep generates SDL_VIDEOEXPOSE */
// QZ_RegisterForSleepNotifications();
}

@ -14,7 +14,7 @@
#include "../variables.h"
#include "../genworld.h"
#include "../fileio.h"
#include "../blitter/blitter.hpp"
#include "../blitter/factory.hpp"
#include "dedicated_v.h"
#ifdef BEOS_NET_SERVER
@ -128,8 +128,6 @@ static const char *DedicatedVideoStart(const char * const *parm)
_screen.width = _screen.pitch = _cur_resolution[0];
_screen.height = _cur_resolution[1];
_screen.renderer = RendererFactoryBase::SelectRenderer(BlitterFactoryBase::GetCurrentBlitter()->GetRenderer());
if (_screen.renderer == NULL) error("Couldn't load the renderer '%s' the selected blitter depends on", BlitterFactoryBase::GetCurrentBlitter()->GetRenderer());
SetDebugString("net=6");

@ -6,7 +6,7 @@
#include "../variables.h"
#include "../window.h"
#include "../debug.h"
#include "../blitter/blitter.hpp"
#include "../blitter/factory.hpp"
#include "null_v.h"
static const char* NullVideoStart(const char* const* parm)
@ -16,8 +16,6 @@ static const char* NullVideoStart(const char* const* parm)
/* Do not render, nor blit */
DEBUG(misc, 1, "Forcing blitter 'null'...");
BlitterFactoryBase::SelectBlitter("null");
_screen.renderer = RendererFactoryBase::SelectRenderer(BlitterFactoryBase::GetCurrentBlitter()->GetRenderer());
if (_screen.renderer == NULL) error("Couldn't load the renderer '%s' the selected blitter depends on", BlitterFactoryBase::GetCurrentBlitter()->GetRenderer());
return NULL;
}

@ -13,8 +13,7 @@
#include "../window.h"
#include "../network/network.h"
#include "../variables.h"
#include "../blitter/blitter.hpp"
#include "../renderer/renderer.hpp"
#include "../blitter/factory.hpp"
#include "sdl_v.h"
#include <SDL.h>
@ -205,8 +204,6 @@ static bool CreateMainSurface(int w, int h)
_screen.width = newscreen->w;
_screen.height = newscreen->h;
_screen.pitch = newscreen->pitch / (bpp / 8);
_screen.renderer = RendererFactoryBase::SelectRenderer(BlitterFactoryBase::GetCurrentBlitter()->GetRenderer());
if (_screen.renderer == NULL) error("Couldn't load the renderer '%s' the selected blitter depends on", BlitterFactoryBase::GetCurrentBlitter()->GetRenderer());
_sdl_screen = newscreen;
InitPalette();

@ -653,8 +653,6 @@ static bool AllocateDibSection(int w, int h)
_screen.width = w;
_screen.pitch = ALIGN(w, 4);
_screen.height = h;
_screen.renderer = RendererFactoryBase::SelectRenderer(BlitterFactoryBase::GetCurrentBlitter()->GetRenderer());
if (_screen.renderer == NULL) error("Couldn't load the renderer '%s' the selected blitter depends on", BlitterFactoryBase::GetCurrentBlitter()->GetRenderer());
bi = (BITMAPINFO*)alloca(sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256);
memset(bi, 0, sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256);
bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);

@ -24,6 +24,7 @@
#include "variables.h"
#include "train.h"
#include "roadveh.h"
#include "blitter/factory.hpp"
#define VIEWPORT_DRAW_MEM (65536 * 2)
@ -1269,7 +1270,7 @@ void ViewportDoDraw(const ViewPort *vp, int left, int top, int right, int bottom
x = UnScaleByZoom(vd.dpi.left - (vp->virtual_left & mask), vp->zoom) + vp->left;
y = UnScaleByZoom(vd.dpi.top - (vp->virtual_top & mask), vp->zoom) + vp->top;
vd.dpi.dst_ptr = _screen.renderer->MoveTo(old_dpi->dst_ptr, x - old_dpi->left, y - old_dpi->top);
vd.dpi.dst_ptr = BlitterFactoryBase::GetCurrentBlitter()->MoveTo(old_dpi->dst_ptr, x - old_dpi->left, y - old_dpi->top);
vd.parent_list = parent_list;
vd.eof_parent_list = endof(parent_list);

@ -17,6 +17,7 @@
#include "table/sprites.h"
#include "genworld.h"
#include "helpers.hpp"
#include "blitter/factory.hpp"
/* delta between mouse cursor and upper left corner of dragged window */
static Point _drag_delta;
@ -270,7 +271,7 @@ static void DrawOverlappedWindow(Window* const *wz, int left, int top, int right
dp->left = left - (*wz)->left;
dp->top = top - (*wz)->top;
dp->pitch = _screen.pitch;
dp->dst_ptr = _screen.renderer->MoveTo(_screen.dst_ptr, left, top);
dp->dst_ptr = BlitterFactoryBase::GetCurrentBlitter()->MoveTo(_screen.dst_ptr, left, top);
dp->zoom = ZOOM_LVL_NORMAL;
CallWindowEventNP(*wz, WE_PAINT);
}

Loading…
Cancel
Save