Fix #111466: GPU: Don't add Textures twice to the same FrameBuffer
Avoid Textures running out of fb_ attachments and/or removing previously added FrameBuffer GPUAttachments during the FrameBuffer configuration process. Pull Request: https://projects.blender.org/blender/blender/pulls/111531
This commit is contained in:
@@ -109,16 +109,15 @@ void FrameBuffer::attachment_set(GPUAttachmentType type, const GPUAttachment &ne
|
||||
reinterpret_cast<Texture *>(attachment.tex)->detach_from(this);
|
||||
}
|
||||
|
||||
attachment = new_attachment;
|
||||
|
||||
/* Might be null if this is for unbinding. */
|
||||
if (attachment.tex) {
|
||||
reinterpret_cast<Texture *>(attachment.tex)->attach_to(this, type);
|
||||
if (new_attachment.tex) {
|
||||
reinterpret_cast<Texture *>(new_attachment.tex)->attach_to(this, type);
|
||||
}
|
||||
else {
|
||||
/* GPU_ATTACHMENT_NONE */
|
||||
}
|
||||
|
||||
attachment = new_attachment;
|
||||
dirty_attachments_ = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -190,6 +190,17 @@ void Texture::usage_set(eGPUTextureUsage usage_flags)
|
||||
|
||||
void Texture::attach_to(FrameBuffer *fb, GPUAttachmentType type)
|
||||
{
|
||||
for (int i = 0; i < ARRAY_SIZE(fb_); i++) {
|
||||
if (fb_[i] == fb) {
|
||||
/* Already stores a reference */
|
||||
if (fb_attachment_[i] != type) {
|
||||
/* Ensure it's not attached twice to the same FrameBuffer. */
|
||||
fb_[i]->attachment_remove(fb_attachment_[i]);
|
||||
fb_attachment_[i] = type;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < ARRAY_SIZE(fb_); i++) {
|
||||
if (fb_[i] == nullptr) {
|
||||
fb_attachment_[i] = type;
|
||||
|
||||
Reference in New Issue
Block a user