Merge pull request #39774 from lawnjelly/kessel_tex_wrapping_fix

GLES2 Batching - Fix texture wrapping state bug.
This commit is contained in:
Rémi Verschelde 2020-06-23 10:17:52 +02:00 committed by GitHub
commit 7ec072f7e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 4 deletions

View File

@ -659,13 +659,22 @@ void RasterizerCanvasGLES2::_batch_render_rects(const Batch &p_batch, Rasterizer
glEnableVertexAttribArray(VS::ARRAY_COLOR);
}
// We only want to set the GL wrapping mode if the texture is not already tiled (i.e. set in Import).
// This is an optimization left over from the legacy renderer.
// If we DID set tiling in the API, and reverted to clamped, then the next draw using this texture
// may use clamped mode incorrectly.
bool tex_is_already_tiled = tex.flags & VS::TEXTURE_FLAG_REPEAT;
switch (tex.tile_mode) {
case BatchTex::TILE_FORCE_REPEAT: {
state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_FORCE_REPEAT, true);
} break;
case BatchTex::TILE_NORMAL: {
// if the texture is imported as tiled, no need to set GL state, as it will already be bound with repeat
if (!tex_is_already_tiled) {
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
}
} break;
default: {
} break;
@ -689,8 +698,11 @@ void RasterizerCanvasGLES2::_batch_render_rects(const Batch &p_batch, Rasterizer
state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_FORCE_REPEAT, false);
} break;
case BatchTex::TILE_NORMAL: {
// if the texture is imported as tiled, no need to revert GL state
if (!tex_is_already_tiled) {
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
} break;
default: {
} break;