From 71f5789d8f4ca38aed63b93a287739946abd766a Mon Sep 17 00:00:00 2001 From: Nikita Lutsenko Date: Wed, 27 Sep 2023 07:25:43 -0700 Subject: [PATCH] igl | opengl | Properly support IMG_multisampled_render_to_texture when EXT_multisampled_render_to_texture is not supported. Summary: https://registry.khronos.org/OpenGL/extensions/IMG/IMG_multisampled_render_to_texture.txt unlike newer version https://registry.khronos.org/OpenGL/extensions/EXT/EXT_multisampled_render_to_texture.txt supports only GL_FRAMEBUFFER and not GL_READ/DRAW_FRAMEBUFFER. Fix the usage within our stack, as it will just result in GL_INVALID_ENUM Reviewed By: dmannemela Differential Revision: D49675129 fbshipit-source-id: 13d73503567fc4bf5e4df076b68184a8c0855619 --- src/igl/opengl/TextureBufferBase.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/igl/opengl/TextureBufferBase.cpp b/src/igl/opengl/TextureBufferBase.cpp index 78a2bad27a..6c3953296e 100644 --- a/src/igl/opengl/TextureBufferBase.cpp +++ b/src/igl/opengl/TextureBufferBase.cpp @@ -66,10 +66,11 @@ void TextureBufferBase::attachAsColor(uint32_t index, const AttachmentParams& pa void TextureBufferBase::attach(GLenum attachment, const AttachmentParams& params, GLuint textureID) { - GLenum target = target_ == GL_TEXTURE_CUBE_MAP ? GL_TEXTURE_CUBE_MAP_POSITIVE_X + params.face - : target_; + const GLenum target = + target_ == GL_TEXTURE_CUBE_MAP ? GL_TEXTURE_CUBE_MAP_POSITIVE_X + params.face : target_; GLenum framebufferTarget = GL_FRAMEBUFFER; - if (getContext().deviceFeatures().hasFeature(DeviceFeatures::ReadWriteFramebuffer)) { + const auto& deviceFeatures = getContext().deviceFeatures(); + if (deviceFeatures.hasFeature(DeviceFeatures::ReadWriteFramebuffer)) { framebufferTarget = params.read ? GL_READ_FRAMEBUFFER : GL_DRAW_FRAMEBUFFER; } const auto numSamples = getSamples(); @@ -89,6 +90,13 @@ void TextureBufferBase::attach(GLenum attachment, 0, 2); } else { + // `IMG_multisampled_render_to_texture` unlike `EXT_multisampled_render_to_texture`, + // only supports GL_FRAMEBUFFER, not GL_DRAW/READ_FRAMEBUFFER + if ((framebufferTarget == GL_DRAW_FRAMEBUFFER || framebufferTarget == GL_READ_FRAMEBUFFER) && + !deviceFeatures.hasExtension(Extensions::MultiSampleExt) && + deviceFeatures.hasExtension(Extensions::MultiSampleImg)) { + framebufferTarget = GL_FRAMEBUFFER; + } getContext().framebufferTexture2DMultisample( framebufferTarget, attachment, target, textureID, params.mipLevel, getSamples()); }