Skip to content

Commit

Permalink
Merge pull request #44790 from lawnjelly/ewok_ninepatch_proxy
Browse files Browse the repository at this point in the history
Batching - fix ninepatch proxy textures (e.g. animated)
  • Loading branch information
akien-mga authored Dec 29, 2020
2 parents fb9f723 + 1e99e89 commit d839afd
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions drivers/gles_common/rasterizer_canvas_batcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -605,17 +605,30 @@ class RasterizerCanvasBatcher {
return TM_ALL;
}
bool _software_skin_poly(RasterizerCanvas::Item::CommandPolygon *p_poly, RasterizerCanvas::Item *p_item, BatchVertex *bvs, BatchColor *vertex_colors, const FillState &p_fill_state, const BatchColor *p_precalced_colors);

typename T_STORAGE::Texture *_get_canvas_texture(const RID &p_texture) const {
if (p_texture.is_valid()) {

typename T_STORAGE::Texture *texture = get_storage()->texture_owner.getornull(p_texture);

if (texture) {

// could be a proxy texture (e.g. animated)
if (texture->proxy) {
// take care to prevent infinite loop
int count = 0;
while (texture->proxy) {
texture = texture->proxy;
count++;
ERR_FAIL_COND_V_MSG(count == 16, nullptr, "Texture proxy infinite loop detected.");
}
}

return texture->get_ptr();
}
}

return 0;
return nullptr;
}

public:
Expand Down Expand Up @@ -1351,13 +1364,14 @@ PREAMBLE(bool)::_prefill_line(RasterizerCanvas::Item::CommandLine *p_line, FillS
T_PREAMBLE
template <bool SEND_LIGHT_ANGLES>
bool C_PREAMBLE::_prefill_ninepatch(RasterizerCanvas::Item::CommandNinePatch *p_np, FillState &r_fill_state, int &r_command_start, int command_num, int command_count, RasterizerCanvas::Item *p_item, bool multiply_final_modulate) {
typename T_STORAGE::Texture *tex = get_storage()->texture_owner.getornull(p_np->texture);
typename T_STORAGE::Texture *tex = _get_canvas_texture(p_np->texture);

if (!tex) {
// FIXME: Handle textureless ninepatch gracefully
WARN_PRINT("NinePatch without texture not supported yet, skipping.");
return false;
}

if (tex->width == 0 || tex->height == 0) {
WARN_PRINT("Cannot set empty texture to NinePatch.");
return false;
Expand Down

0 comments on commit d839afd

Please sign in to comment.