Merge pull request #58357 from BastiaanOlij/fix_external_viewport_texture

This commit is contained in:
Rémi Verschelde 2022-03-07 13:18:33 +01:00 committed by GitHub
commit 2dec5db5df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 148 deletions

View File

@ -5340,20 +5340,19 @@ void RasterizerStorageGLES2::_render_target_clear(RenderTarget *rt) {
rt->fbo = 0; 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) { if (rt->external.fbo != 0) {
// free this // free this
glDeleteFramebuffers(1, &rt->external.fbo); glDeleteFramebuffers(1, &rt->external.fbo);
// clean up our texture // reset our texture back to the original
Texture *t = texture_owner.get(rt->external.texture); tex->tex_id = rt->color;
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);
if (rt->external.depth != 0 && rt->external.depth_owned) { if (rt->external.depth != 0 && rt->external.depth_owned) {
glDeleteRenderbuffers(1, &rt->external.depth); glDeleteRenderbuffers(1, &rt->external.depth);
@ -5375,13 +5374,6 @@ void RasterizerStorageGLES2::_render_target_clear(RenderTarget *rt) {
rt->depth = 0; 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) { if (rt->copy_screen_effect.color) {
glDeleteFramebuffers(1, &rt->copy_screen_effect.fbo); glDeleteFramebuffers(1, &rt->copy_screen_effect.fbo);
rt->copy_screen_effect.fbo = 0; 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); RenderTarget *rt = render_target_owner.getornull(p_render_target);
ERR_FAIL_COND_V(!rt, RID()); ERR_FAIL_COND_V(!rt, RID());
if (rt->external.fbo == 0) {
return rt->texture; return rt->texture;
} else {
return rt->external.texture;
}
} }
uint32_t RasterizerStorageGLES2::render_target_get_depth_texture_id(RID p_render_target) const { 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); glDeleteRenderbuffers(1, &rt->external.depth);
} }
// clean up our texture // reset our texture back to the original
Texture *t = texture_owner.get(rt->external.texture); Texture *t = texture_owner.get(rt->texture);
t->tex_id = 0; t->tex_id = rt->color;
t->alloc_height = 0; t->width = rt->width;
t->alloc_width = 0; t->alloc_width = rt->width;
t->width = 0; t->height = rt->height;
t->height = 0; t->alloc_height = rt->height;
t->active = false;
texture_owner.free(rt->external.texture);
memdelete(t);
rt->external.fbo = 0; rt->external.fbo = 0;
rt->external.color = 0; rt->external.color = 0;
rt->external.depth = 0; rt->external.depth = 0;
} }
} else { } else {
Texture *t;
if (rt->external.fbo == 0) { if (rt->external.fbo == 0) {
// create our fbo // create our fbo
glGenFramebuffers(1, &rt->external.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 // bind our frame buffer
glBindFramebuffer(GL_FRAMEBUFFER, rt->external.fbo); 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;
rt->external.color = p_texture_id; 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->width = rt->width;
t->height = rt->height; t->height = rt->height;
t->alloc_height = rt->width; t->alloc_height = rt->width;

View File

@ -1225,7 +1225,6 @@ public:
GLuint color; GLuint color;
GLuint depth; GLuint depth;
bool depth_owned; bool depth_owned;
RID texture;
External() : External() :
fbo(0), fbo(0),

View File

@ -6853,26 +6853,6 @@ void RasterizerStorageGLES3::_render_target_clear(RenderTarget *rt) {
rt->exposure.fbo = 0; 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); Texture *tex = texture_owner.get(rt->texture);
tex->alloc_height = 0; tex->alloc_height = 0;
tex->alloc_width = 0; tex->alloc_width = 0;
@ -6880,6 +6860,18 @@ void RasterizerStorageGLES3::_render_target_clear(RenderTarget *rt) {
tex->height = 0; tex->height = 0;
tex->active = false; 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++) { for (int i = 0; i < 2; i++) {
if (rt->effects.mip_maps[i].color) { if (rt->effects.mip_maps[i].color) {
for (int j = 0; j < rt->effects.mip_maps[i].sizes.size(); j++) { 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); RenderTarget *rt = render_target_owner.getornull(p_render_target);
ERR_FAIL_COND_V(!rt, RID()); ERR_FAIL_COND_V(!rt, RID());
if (rt->external.fbo == 0) {
return rt->texture; return rt->texture;
} else {
return rt->external.texture;
}
} }
uint32_t RasterizerStorageGLES3::render_target_get_depth_texture_id(RID p_render_target) const { 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 // free this
glDeleteFramebuffers(1, &rt->external.fbo); glDeleteFramebuffers(1, &rt->external.fbo);
// clean up our texture // reset our texture back to the original
Texture *t = texture_owner.get(rt->external.texture); Texture *t = texture_owner.get(rt->texture);
t->tex_id = 0; t->tex_id = rt->color;
t->alloc_height = 0; t->width = rt->width;
t->alloc_width = 0; t->alloc_width = rt->width;
t->width = 0; t->height = rt->height;
t->height = 0; t->alloc_height = rt->height;
t->active = false;
texture_owner.free(rt->external.texture);
memdelete(t);
rt->external.fbo = 0; rt->external.fbo = 0;
rt->external.color = 0; rt->external.color = 0;
rt->external.depth = 0; rt->external.depth = 0;
} }
} else { } else {
Texture *t;
if (rt->external.fbo == 0) { if (rt->external.fbo == 0) {
// create our fbo // create our fbo
glGenFramebuffers(1, &rt->external.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 // bind our frame buffer
glBindFramebuffer(GL_FRAMEBUFFER, rt->external.fbo); 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;
rt->external.color = p_texture_id; 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->width = rt->width;
t->height = rt->height; t->height = rt->height;
t->alloc_height = rt->width; t->alloc_height = rt->width;
t->alloc_width = rt->height; 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 // set our texture as the destination for our framebuffer
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, p_texture_id, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, p_texture_id, 0);

View File

@ -1381,7 +1381,6 @@ public:
GLuint fbo; GLuint fbo;
GLuint color; GLuint color;
GLuint depth; GLuint depth;
RID texture;
External() : External() :
fbo(0), fbo(0),