diff --git a/drivers/gles2/rasterizer_storage_gles2.cpp b/drivers/gles2/rasterizer_storage_gles2.cpp index cb3d9734cb9..6aa30809a2d 100644 --- a/drivers/gles2/rasterizer_storage_gles2.cpp +++ b/drivers/gles2/rasterizer_storage_gles2.cpp @@ -5340,20 +5340,19 @@ void RasterizerStorageGLES2::_render_target_clear(RenderTarget *rt) { rt->fbo = 0; } + Texture *tex = texture_owner.get(rt->texture); + tex->alloc_height = 0; + tex->alloc_width = 0; + tex->width = 0; + tex->height = 0; + tex->active = false; + if (rt->external.fbo != 0) { // free this glDeleteFramebuffers(1, &rt->external.fbo); - // clean up our texture - Texture *t = texture_owner.get(rt->external.texture); - t->tex_id = 0; - t->alloc_height = 0; - t->alloc_width = 0; - t->width = 0; - t->height = 0; - t->active = false; - texture_owner.free(rt->external.texture); - memdelete(t); + // reset our texture back to the original + tex->tex_id = rt->color; if (rt->external.depth != 0 && rt->external.depth_owned) { glDeleteRenderbuffers(1, &rt->external.depth); @@ -5375,13 +5374,6 @@ void RasterizerStorageGLES2::_render_target_clear(RenderTarget *rt) { rt->depth = 0; } - Texture *tex = texture_owner.get(rt->texture); - tex->alloc_height = 0; - tex->alloc_width = 0; - tex->width = 0; - tex->height = 0; - tex->active = false; - if (rt->copy_screen_effect.color) { glDeleteFramebuffers(1, &rt->copy_screen_effect.fbo); rt->copy_screen_effect.fbo = 0; @@ -5477,11 +5469,7 @@ RID RasterizerStorageGLES2::render_target_get_texture(RID p_render_target) const RenderTarget *rt = render_target_owner.getornull(p_render_target); ERR_FAIL_COND_V(!rt, RID()); - if (rt->external.fbo == 0) { - return rt->texture; - } else { - return rt->external.texture; - } + return rt->texture; } uint32_t RasterizerStorageGLES2::render_target_get_depth_texture_id(RID p_render_target) const { @@ -5509,68 +5497,32 @@ void RasterizerStorageGLES2::render_target_set_external_texture(RID p_render_tar glDeleteRenderbuffers(1, &rt->external.depth); } - // clean up our texture - Texture *t = texture_owner.get(rt->external.texture); - t->tex_id = 0; - t->alloc_height = 0; - t->alloc_width = 0; - t->width = 0; - t->height = 0; - t->active = false; - texture_owner.free(rt->external.texture); - memdelete(t); + // reset our texture back to the original + Texture *t = texture_owner.get(rt->texture); + t->tex_id = rt->color; + t->width = rt->width; + t->alloc_width = rt->width; + t->height = rt->height; + t->alloc_height = rt->height; rt->external.fbo = 0; rt->external.color = 0; rt->external.depth = 0; } } else { - Texture *t; - if (rt->external.fbo == 0) { // create our fbo glGenFramebuffers(1, &rt->external.fbo); - glBindFramebuffer(GL_FRAMEBUFFER, rt->external.fbo); - - // allocate a texture - t = memnew(Texture); - - t->type = VS::TEXTURE_TYPE_2D; - t->flags = 0; - t->width = 0; - t->height = 0; - t->alloc_height = 0; - t->alloc_width = 0; - t->format = Image::FORMAT_RGBA8; - t->target = GL_TEXTURE_2D; - t->gl_format_cache = 0; - t->gl_internal_format_cache = 0; - t->gl_type_cache = 0; - t->data_size = 0; - t->compressed = false; - t->srgb = false; - t->total_data_size = 0; - t->ignore_mipmaps = false; - t->mipmaps = 1; - t->active = true; - t->tex_id = 0; - t->render_target = rt; - - rt->external.texture = texture_owner.make_rid(t); - - } else { - // bind our frame buffer - glBindFramebuffer(GL_FRAMEBUFFER, rt->external.fbo); - - // find our texture - t = texture_owner.get(rt->external.texture); } - // set our texture - t->tex_id = p_texture_id; + // bind our frame buffer + glBindFramebuffer(GL_FRAMEBUFFER, rt->external.fbo); + rt->external.color = p_texture_id; - // size shouldn't be different + // Set our texture to the new image, note that we expect formats to be the same (or compatible) so we don't change those + Texture *t = texture_owner.get(rt->texture); + t->tex_id = p_texture_id; t->width = rt->width; t->height = rt->height; t->alloc_height = rt->width; diff --git a/drivers/gles2/rasterizer_storage_gles2.h b/drivers/gles2/rasterizer_storage_gles2.h index 58c3f7b02ca..14bd9db4e78 100644 --- a/drivers/gles2/rasterizer_storage_gles2.h +++ b/drivers/gles2/rasterizer_storage_gles2.h @@ -1225,7 +1225,6 @@ public: GLuint color; GLuint depth; bool depth_owned; - RID texture; External() : fbo(0), diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp index 131ef8ffb1d..48dadc9d378 100644 --- a/drivers/gles3/rasterizer_storage_gles3.cpp +++ b/drivers/gles3/rasterizer_storage_gles3.cpp @@ -6853,26 +6853,6 @@ void RasterizerStorageGLES3::_render_target_clear(RenderTarget *rt) { rt->exposure.fbo = 0; } - if (rt->external.fbo != 0) { - // free this - glDeleteFramebuffers(1, &rt->external.fbo); - - // clean up our texture - Texture *t = texture_owner.get(rt->external.texture); - t->tex_id = 0; - t->alloc_height = 0; - t->alloc_width = 0; - t->width = 0; - t->height = 0; - t->active = false; - texture_owner.free(rt->external.texture); - memdelete(t); - - rt->external.fbo = 0; - rt->external.color = 0; - rt->external.depth = 0; - } - Texture *tex = texture_owner.get(rt->texture); tex->alloc_height = 0; tex->alloc_width = 0; @@ -6880,6 +6860,18 @@ void RasterizerStorageGLES3::_render_target_clear(RenderTarget *rt) { tex->height = 0; tex->active = false; + if (rt->external.fbo != 0) { + // free this + glDeleteFramebuffers(1, &rt->external.fbo); + + // reset our texture back to the original + tex->tex_id = rt->color; + + rt->external.fbo = 0; + rt->external.color = 0; + rt->external.depth = 0; + } + for (int i = 0; i < 2; i++) { if (rt->effects.mip_maps[i].color) { for (int j = 0; j < rt->effects.mip_maps[i].sizes.size(); j++) { @@ -7343,11 +7335,7 @@ RID RasterizerStorageGLES3::render_target_get_texture(RID p_render_target) const RenderTarget *rt = render_target_owner.getornull(p_render_target); ERR_FAIL_COND_V(!rt, RID()); - if (rt->external.fbo == 0) { - return rt->texture; - } else { - return rt->external.texture; - } + return rt->texture; } uint32_t RasterizerStorageGLES3::render_target_get_depth_texture_id(RID p_render_target) const { @@ -7377,74 +7365,37 @@ void RasterizerStorageGLES3::render_target_set_external_texture(RID p_render_tar // free this glDeleteFramebuffers(1, &rt->external.fbo); - // clean up our texture - Texture *t = texture_owner.get(rt->external.texture); - t->tex_id = 0; - t->alloc_height = 0; - t->alloc_width = 0; - t->width = 0; - t->height = 0; - t->active = false; - texture_owner.free(rt->external.texture); - memdelete(t); + // reset our texture back to the original + Texture *t = texture_owner.get(rt->texture); + t->tex_id = rt->color; + t->width = rt->width; + t->alloc_width = rt->width; + t->height = rt->height; + t->alloc_height = rt->height; rt->external.fbo = 0; rt->external.color = 0; rt->external.depth = 0; } } else { - Texture *t; - if (rt->external.fbo == 0) { // create our fbo glGenFramebuffers(1, &rt->external.fbo); - glBindFramebuffer(GL_FRAMEBUFFER, rt->external.fbo); - - // allocate a texture - t = memnew(Texture); - - t->type = VS::TEXTURE_TYPE_2D; - t->flags = 0; - t->width = 0; - t->height = 0; - t->alloc_height = 0; - t->alloc_width = 0; - t->format = Image::FORMAT_RGBA8; - t->target = GL_TEXTURE_2D; - t->gl_format_cache = 0; - t->gl_internal_format_cache = 0; - t->gl_type_cache = 0; - t->data_size = 0; - t->compressed = false; - t->srgb = false; - t->total_data_size = 0; - t->ignore_mipmaps = false; - t->mipmaps = 1; - t->active = true; - t->tex_id = 0; - t->render_target = rt; - - rt->external.texture = texture_owner.make_rid(t); - } else { - // bind our frame buffer - glBindFramebuffer(GL_FRAMEBUFFER, rt->external.fbo); - - // find our texture - t = texture_owner.get(rt->external.texture); } - // set our texture - t->tex_id = p_texture_id; + // bind our frame buffer + glBindFramebuffer(GL_FRAMEBUFFER, rt->external.fbo); + rt->external.color = p_texture_id; - // size shouldn't be different + // Set our texture to the new image, note that we expect formats to be the same (or compatible) so we don't change those + Texture *t = texture_owner.get(rt->texture); + t->tex_id = p_texture_id; t->width = rt->width; t->height = rt->height; t->alloc_height = rt->width; t->alloc_width = rt->height; - // is there a point to setting the internal formats? we don't know them.. - // set our texture as the destination for our framebuffer glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, p_texture_id, 0); diff --git a/drivers/gles3/rasterizer_storage_gles3.h b/drivers/gles3/rasterizer_storage_gles3.h index cea3502939f..5c28b5de750 100644 --- a/drivers/gles3/rasterizer_storage_gles3.h +++ b/drivers/gles3/rasterizer_storage_gles3.h @@ -1381,7 +1381,6 @@ public: GLuint fbo; GLuint color; GLuint depth; - RID texture; External() : fbo(0),