Process only animated tiles

Trying to make copies of static tiles and animating
them has bad results on some GLES devices
This commit is contained in:
Varun Patil 2019-05-12 21:22:05 +05:30
parent bcdd187f69
commit 0f4de4b5f7
4 changed files with 52 additions and 14 deletions

View File

@ -6,6 +6,14 @@ uniform vec2 translation;
uniform float aniIndex; uniform float aniIndex;
uniform float t1Ani;
uniform float t2Ani;
uniform float t3Ani;
uniform float t4Ani;
uniform float t5Ani;
uniform float t6Ani;
uniform float t7Ani;
attribute vec2 position; attribute vec2 position;
attribute vec2 texCoord; attribute vec2 texCoord;
@ -20,6 +28,16 @@ void main()
vec2 tex = texCoord; vec2 tex = texCoord;
lowp float pred = float(tex.x <= atAreaW && tex.y <= atAreaH); lowp float pred = float(tex.x <= atAreaW && tex.y <= atAreaH);
highp int tileIndex = int(tex.y / 128.0) + 1;
if ((tileIndex == 1 && t1Ani >= 1.0) ||
(tileIndex == 2 && t2Ani >= 1.0) ||
(tileIndex == 3 && t3Ani >= 1.0) ||
(tileIndex == 4 && t4Ani >= 1.0) ||
(tileIndex == 5 && t5Ani >= 1.0) ||
(tileIndex == 6 && t6Ani >= 1.0) ||
(tileIndex == 7 && t7Ani >= 1.0))
tex.x += aniIndex * atAniOffset * pred; tex.x += aniIndex * atAniOffset * pred;
gl_Position = projMat * vec4(position + translation, 0, 1); gl_Position = projMat * vec4(position + translation, 0, 1);

View File

@ -520,6 +520,13 @@ TilemapShader::TilemapShader()
ShaderBase::init(); ShaderBase::init();
GET_U(aniIndex); GET_U(aniIndex);
GET_U(t1Ani);
GET_U(t2Ani);
GET_U(t3Ani);
GET_U(t4Ani);
GET_U(t5Ani);
GET_U(t6Ani);
GET_U(t7Ani);
} }
void TilemapShader::setAniIndex(int value) void TilemapShader::setAniIndex(int value)
@ -527,6 +534,16 @@ void TilemapShader::setAniIndex(int value)
gl.Uniform1f(u_aniIndex, value); gl.Uniform1f(u_aniIndex, value);
} }
void TilemapShader::setAniIndices(int value[])
{
gl.Uniform1f(u_t1Ani, value[0]);
gl.Uniform1f(u_t2Ani, value[1]);
gl.Uniform1f(u_t3Ani, value[2]);
gl.Uniform1f(u_t4Ani, value[3]);
gl.Uniform1f(u_t5Ani, value[4]);
gl.Uniform1f(u_t6Ani, value[5]);
gl.Uniform1f(u_t7Ani, value[6]);
}
FlashMapShader::FlashMapShader() FlashMapShader::FlashMapShader()

View File

@ -219,9 +219,17 @@ public:
TilemapShader(); TilemapShader();
void setAniIndex(int value); void setAniIndex(int value);
void setAniIndices(int value[]);
private: private:
GLint u_aniIndex; GLint u_aniIndex;
GLint u_t1Ani;
GLint u_t2Ani;
GLint u_t3Ani;
GLint u_t4Ani;
GLint u_t5Ani;
GLint u_t6Ani;
GLint u_t7Ani;
}; };
class FlashMapShader : public ShaderBase class FlashMapShader : public ShaderBase

View File

@ -281,6 +281,7 @@ struct TilemapPrivate
/* Animation state */ /* Animation state */
uint8_t frameIdx; uint8_t frameIdx;
uint8_t aniIdx; uint8_t aniIdx;
int aniIndices[7];
} tiles; } tiles;
FlashMap flashMap; FlashMap flashMap;
@ -432,8 +433,12 @@ struct TilemapPrivate
usableATs.push_back(i); usableATs.push_back(i);
if (autotiles[i]->width() > autotileW) if (autotiles[i]->width() > autotileW) {
animatedATs.push_back(i); animatedATs.push_back(i);
tiles.aniIndices[i] = 2;
} else {
tiles.aniIndices[i] = 0;
}
} }
tiles.animated = !animatedATs.empty(); tiles.animated = !animatedATs.empty();
@ -514,20 +519,9 @@ struct TilemapPrivate
GLMeta::blitSource(autotile->getGLTypes()); GLMeta::blitSource(autotile->getGLTypes());
if (blitW <= autotileW && tiles.animated)
{
/* Static autotile */
for (int j = 0; j < 4; ++j)
GLMeta::blitRectangle(IntRect(0, 0, blitW, blitH),
Vec2i(autotileW*j, atInd*autotileH));
}
else
{
/* Animated autotile */
GLMeta::blitRectangle(IntRect(0, 0, blitW, blitH), GLMeta::blitRectangle(IntRect(0, 0, blitW, blitH),
Vec2i(0, atInd*autotileH)); Vec2i(0, atInd*autotileH));
} }
}
GLMeta::blitEnd(); GLMeta::blitEnd();
@ -771,6 +765,7 @@ struct TilemapPrivate
TilemapShader &tilemapShader = shState->shaders().tilemap; TilemapShader &tilemapShader = shState->shaders().tilemap;
tilemapShader.bind(); tilemapShader.bind();
tilemapShader.setAniIndex(tiles.frameIdx); tilemapShader.setAniIndex(tiles.frameIdx);
tilemapShader.setAniIndices(tiles.aniIndices);
shaderVar = &tilemapShader; shaderVar = &tilemapShader;
} }
else else