texture animation optimization

This commit is contained in:
@clasher113 2024-06-13 17:34:36 +03:00
parent c88bbe7fcb
commit 22b3d84ee0
2 changed files with 5 additions and 18 deletions

View File

@ -235,8 +235,10 @@ static TextureAnimation create_animation(
uint srcWidth = srcTex->getWidth(); uint srcWidth = srcTex->getWidth();
uint srcHeight = srcTex->getHeight(); uint srcHeight = srcTex->getHeight();
frame.dstPos = glm::ivec2(region.u1 * dstWidth, region.v1 * dstHeight); const int extension = 2;
frame.size = glm::ivec2(region.u2 * dstWidth, region.v2 * dstHeight) - frame.dstPos;
frame.dstPos = glm::ivec2(region.u1 * dstWidth, region.v1 * dstHeight) - extension;
frame.size = glm::ivec2(region.u2 * dstWidth, region.v2 * dstHeight) - frame.dstPos + extension;
for (const auto& elem : frameList) { for (const auto& elem : frameList) {
if (!srcAtlas->has(elem.first)) { if (!srcAtlas->has(elem.first)) {
@ -247,7 +249,7 @@ static TextureAnimation create_animation(
if (elem.second > 0) { if (elem.second > 0) {
frame.duration = static_cast<float>(elem.second) / 1000.0f; frame.duration = static_cast<float>(elem.second) / 1000.0f;
} }
frame.srcPos = glm::ivec2(region.u1 * srcWidth, srcHeight - region.v2 * srcHeight); frame.srcPos = glm::ivec2(region.u1 * srcWidth, srcHeight - region.v2 * srcHeight) - extension;
animation.addFrame(frame); animation.addFrame(frame);
} }
return animation; return animation;

View File

@ -52,21 +52,6 @@ void TextureAnimator::update(float delta) {
float srcPosY = elem.srcTexture->getHeight() - frame.size.y - frame.srcPos.y; // vertical flip float srcPosY = elem.srcTexture->getHeight() - frame.size.y - frame.srcPos.y; // vertical flip
// Extensions
const int ext = 2;
for (int y = -1; y <= 1; y++) {
for (int x = -1; x <= 1; x++) {
if (x == 0 && y == 0)
continue;
glBlitFramebuffer(
frame.srcPos.x, srcPosY, frame.srcPos.x + frame.size.x, srcPosY + frame.size.y,
frame.dstPos.x+x*ext, frame.dstPos.y+y*ext,
frame.dstPos.x + frame.size.x+x*ext, frame.dstPos.y + frame.size.y+y*ext,
GL_COLOR_BUFFER_BIT, GL_NEAREST
);
}
}
glBlitFramebuffer( glBlitFramebuffer(
frame.srcPos.x, srcPosY, frame.srcPos.x, srcPosY,
frame.srcPos.x + frame.size.x, frame.srcPos.x + frame.size.x,