TileAtlasVX: Followup fix

Use rectangle intersection to correctly clip source
rectangles with origin != (0,0).
This commit is contained in:
Jonas Kulla 2014-10-03 06:51:39 +02:00
parent db78e55371
commit df73045d81
2 changed files with 26 additions and 14 deletions

View File

@ -93,17 +93,20 @@ struct Vec2i
}
};
struct IntRect
struct IntRect : SDL_Rect
{
int x, y, w, h;
IntRect()
: x(0), y(0), w(0), h(0)
{}
{
x = y = w = h = 0;
}
IntRect(int x, int y, int w, int h)
: x(x), y(y), w(w), h(h)
{}
{
this->x = x;
this->y = y;
this->w = w;
this->h = h;
}
bool operator==(const IntRect &other) const
{

View File

@ -270,6 +270,19 @@ createShadowSet()
return surf;
}
static void doBlit(Bitmap *bm, const IntRect &src, const Vec2i &dst)
{
/* Translate tile to pixel units */
IntRect _src(src.x*32, src.y*32, src.w*32, src.h*32);
Vec2i _dst(dst.x*32, dst.y*32);
IntRect bmr(0, 0, bm->width(), bm->height());
if (!SDL_IntersectRect(&_src, &bmr, &_src))
return;
GLMeta::blitRectangle(_src, _dst);
}
void build(TEXFBO &tf, Bitmap *bitmaps[BM_COUNT])
{
assert(tf.width == ATLASVX_W && tf.height == ATLASVX_H);
@ -296,13 +309,9 @@ void build(TEXFBO &tf, Bitmap *bitmaps[BM_COUNT])
GLMeta::blitSource(bm->getGLTypes()); \
for (size_t i = 0; i < blits##part##N; ++i) \
{\
IntRect src = blits##part[i].src; \
int w = std::min(bm->width(), src.w*32); \
int h = std::min(bm->height(), src.h*32); \
src = IntRect(src.x*32, src.y*32, w, h); \
Vec2i dst = blits##part[i].dst; \
dst = Vec2i(dst.x*32, dst.y*32); \
GLMeta::blitRectangle(src, dst); \
const IntRect &src = blits##part[i].src; \
const Vec2i &dst = blits##part[i].dst; \
doBlit(bm, src, dst); \
} \
}