TileAtlasVX: Followup fix
Use rectangle intersection to correctly clip source rectangles with origin != (0,0).
This commit is contained in:
parent
db78e55371
commit
df73045d81
|
@ -93,17 +93,20 @@ struct Vec2i
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct IntRect
|
struct IntRect : SDL_Rect
|
||||||
{
|
{
|
||||||
int x, y, w, h;
|
|
||||||
|
|
||||||
IntRect()
|
IntRect()
|
||||||
: x(0), y(0), w(0), h(0)
|
{
|
||||||
{}
|
x = y = w = h = 0;
|
||||||
|
}
|
||||||
|
|
||||||
IntRect(int x, int y, int w, int h)
|
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
|
bool operator==(const IntRect &other) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -270,6 +270,19 @@ createShadowSet()
|
||||||
return surf;
|
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])
|
void build(TEXFBO &tf, Bitmap *bitmaps[BM_COUNT])
|
||||||
{
|
{
|
||||||
assert(tf.width == ATLASVX_W && tf.height == ATLASVX_H);
|
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()); \
|
GLMeta::blitSource(bm->getGLTypes()); \
|
||||||
for (size_t i = 0; i < blits##part##N; ++i) \
|
for (size_t i = 0; i < blits##part##N; ++i) \
|
||||||
{\
|
{\
|
||||||
IntRect src = blits##part[i].src; \
|
const IntRect &src = blits##part[i].src; \
|
||||||
int w = std::min(bm->width(), src.w*32); \
|
const Vec2i &dst = blits##part[i].dst; \
|
||||||
int h = std::min(bm->height(), src.h*32); \
|
doBlit(bm, src, dst); \
|
||||||
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); \
|
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue