Skip to content

Commit

Permalink
igl | opengl | Allow depth-only framebuffers
Browse files Browse the repository at this point in the history
Summary: Allow depth-only framebuffers in IGL/OpenGL. This is crucial for shadow mapping.

Reviewed By: MichaelTay

Differential Revision: D50099325

fbshipit-source-id: 2a985567cd4893d5b7aecc4493dc11b08badb573
  • Loading branch information
corporateshark authored and facebook-github-bot committed Oct 10, 2023
1 parent 4bb5dd5 commit 599573b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
14 changes: 0 additions & 14 deletions samples/desktop/Tiny/Tiny_MeshLarge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1781,21 +1781,7 @@ void createShadowMap() {
IGL_ASSERT(ret.isOk());

FramebufferDesc framebufferDesc;

framebufferDesc.depthAttachment.texture = shadowMap;
#if USE_OPENGL_BACKEND
// OpenGL backend requires both color and depth attchments.
auto descColor = TextureDesc::new2D(igl::TextureFormat::RGBA_UNorm8,
w,
h,
TextureDesc::TextureUsageBits::Sampled |
TextureDesc::TextureUsageBits::Attachment,
"shadow color framebuffer");
descColor.numMipLevels = TextureDesc::calcNumMipLevels(w, h);
std::shared_ptr<ITexture> texColor = device_->createTexture(descColor, &ret);
IGL_ASSERT(ret.isOk());
framebufferDesc.colorAttachments[0].texture = texColor;
#endif
fbShadowMap_ = device_->createFramebuffer(framebufferDesc, nullptr);
IGL_ASSERT(fbShadowMap_);
}
Expand Down
6 changes: 5 additions & 1 deletion src/igl/opengl/Framebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,11 @@ Viewport CustomFramebuffer::getViewport() const {
auto texture = getColorAttachment(0);

if (texture == nullptr) {
IGL_ASSERT_MSG(0, "No color attachment in CustomFrameBuffer at index 0");
texture = getDepthAttachment();
}

if (texture == nullptr) {
IGL_ASSERT_MSG(0, "No color/depth attachments in CustomFrameBuffer at index 0");
return {0, 0, 0, 0};
}

Expand Down

0 comments on commit 599573b

Please sign in to comment.