Skip to content

Commit

Permalink
Hydrogent: enabled mesh id picking on OpenGL
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Sep 21, 2023
1 parent c8011a1 commit 4b33030
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions Hydrogent/include/HnRendererImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class HnRendererImpl final : public ObjectBase<IHnRenderer>
pxr::HdRenderPassSharedPtr m_GeometryPass;

RefCntAutoPtr<ITexture> m_MeshIdTexture;
RefCntAutoPtr<ITexture> m_DepthBuffer;

GPUCompletionAwaitQueue<RefCntAutoPtr<ITexture>> m_MeshIdReadBackQueue;
};
Expand Down
14 changes: 14 additions & 0 deletions Hydrogent/src/HnRendererImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,26 @@ void HnRendererImpl::RenderPrimId(IDeviceContext* pContext, ITextureView* pDepth
TexDesc.MipLevels = 1;

m_MeshIdTexture = m_Device.CreateTexture(TexDesc, nullptr);

if (m_Device.GetDeviceInfo().IsGLDevice())
{
// We can't use the default framebuffer's depth buffer with our own render target,
// so we have to create a copy.
m_DepthBuffer.Release();
auto DepthDescCopy = DepthDesc;
DepthDescCopy.Name = "Depth buffer copy";
m_DepthBuffer = m_Device.CreateTexture(DepthDescCopy, nullptr);
}
}

if (m_DepthBuffer)
pDepthBuffer = m_DepthBuffer->GetDefaultView(TEXTURE_VIEW_DEPTH_STENCIL);
ITextureView* pRTVs[] = {m_MeshIdTexture->GetDefaultView(TEXTURE_VIEW_RENDER_TARGET)};
pContext->SetRenderTargets(_countof(pRTVs), pRTVs, pDepthBuffer, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
float ClearColor[] = {0, 0, 0, 0};
pContext->ClearRenderTarget(pRTVs[0], ClearColor, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
if (m_DepthBuffer)
pContext->ClearDepthStencil(pDepthBuffer, CLEAR_DEPTH_FLAG, 1.f, 0, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);

const auto& Meshes = m_RenderDelegate->GetMeshes();
if (Meshes.empty())
Expand Down
4 changes: 2 additions & 2 deletions PBR/src/PBR_Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,11 +768,11 @@ void PBR_Renderer::CreatePSO(IRenderDevice* pDevice, IRenderStateCache* pStateCa
}
PSOCreateInfo.pPS = pMeshIdPS;

PSOCreateInfo.GraphicsPipeline.RasterizerDesc.CullMode = CULL_MODE_NONE;
PSOCreateInfo.GraphicsPipeline.RasterizerDesc.CullMode = CULL_MODE_BACK;

m_MeshIdPSO[0] = Device.CreateGraphicsPipelineState(PSOCreateInfo);

PSOCreateInfo.GraphicsPipeline.RasterizerDesc.CullMode = CULL_MODE_BACK;
PSOCreateInfo.GraphicsPipeline.RasterizerDesc.CullMode = CULL_MODE_NONE;

m_MeshIdPSO[1] = Device.CreateGraphicsPipelineState(PSOCreateInfo);
}
Expand Down

0 comments on commit 4b33030

Please sign in to comment.