GLES2 Batching - Fix FORCE_REPEAT not being set properly on npot hardware

On platforms that don't report support for GL_REPEAT for non power of two textures, the FORCE_REPEAT conditional is used instead. However for rect batches, the conditional was being set AFTER binding the shader, which meant it wasn't being activated.

This PR simply shifts setting the conditional to before the shader bind.
This commit is contained in:
lawnjelly 2020-07-15 09:28:16 +01:00
parent 3de89f78e5
commit 2f983c82c8
1 changed files with 15 additions and 16 deletions

View File

@ -627,16 +627,22 @@ void RasterizerCanvasGLES2::_batch_render_rects(const Batch &p_batch, Rasterizer
sizeof_vert = sizeof(BatchVertexColored); sizeof_vert = sizeof(BatchVertexColored);
} }
// batch tex
const BatchTex &tex = bdata.batch_textures[p_batch.batch_texture_id];
// make sure to set all conditionals BEFORE binding the shader
state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_TEXTURE_RECT, false); state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_TEXTURE_RECT, false);
// force repeat is set if non power of 2 texture, and repeat is needed if hardware doesn't support npot
if (tex.tile_mode == BatchTex::TILE_FORCE_REPEAT) {
state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_FORCE_REPEAT, true);
}
if (state.canvas_shader.bind()) { if (state.canvas_shader.bind()) {
_set_uniforms(); _set_uniforms();
state.canvas_shader.use_material((void *)p_material); state.canvas_shader.use_material((void *)p_material);
} }
// batch tex
const BatchTex &tex = bdata.batch_textures[p_batch.batch_texture_id];
_bind_canvas_texture(tex.RID_texture, tex.RID_normal); _bind_canvas_texture(tex.RID_texture, tex.RID_normal);
// bind the index and vertex buffer // bind the index and vertex buffer
@ -665,19 +671,12 @@ void RasterizerCanvasGLES2::_batch_render_rects(const Batch &p_batch, Rasterizer
// may use clamped mode incorrectly. // may use clamped mode incorrectly.
bool tex_is_already_tiled = tex.flags & VS::TEXTURE_FLAG_REPEAT; bool tex_is_already_tiled = tex.flags & VS::TEXTURE_FLAG_REPEAT;
switch (tex.tile_mode) { if (tex.tile_mode == BatchTex::TILE_NORMAL) {
case BatchTex::TILE_FORCE_REPEAT: { // if the texture is imported as tiled, no need to set GL state, as it will already be bound with repeat
state.canvas_shader.set_conditional(CanvasShaderGLES2::USE_FORCE_REPEAT, true); if (!tex_is_already_tiled) {
} break; glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
case BatchTex::TILE_NORMAL: { glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
// 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;
} }
// we need to convert explicitly from pod Vec2 to Vector2 ... // we need to convert explicitly from pod Vec2 to Vector2 ...