git.s-ol.nu ~forks/DiligentTools / aaba2d0
Added support for 1+ textures to ImGui renderer This was not possible to use textures other than the font texture with the ImGui renderer. To address that limitation, this commit adds support for one or more textures by updating the SRB's variable when needed. Thomas Tissot 10 months ago
1 changed file(s) with 15 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
335335
336336 ShaderResourceVariableDesc Variables[] =
337337 {
338 {SHADER_TYPE_PIXEL, "Texture", SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE} //
338 {SHADER_TYPE_PIXEL, "Texture", SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC} //
339339 };
340340 PSODesc.ResourceLayout.Variables = Variables;
341341 PSODesc.ResourceLayout.NumVariables = _countof(Variables);
392392
393393 m_pSRB.Release();
394394 m_pPSO->CreateShaderResourceBinding(&m_pSRB, true);
395 m_pSRB->GetVariableByName(SHADER_TYPE_PIXEL, "Texture")->Set(m_pFontSRV);
396395
397396 // Store our identifier
398397 io.Fonts->TexID = (ImTextureID)m_pFontSRV;
634633 pCtx->SetVertexBuffers(0, 1, pVBs, Offsets, RESOURCE_STATE_TRANSITION_MODE_TRANSITION, SET_VERTEX_BUFFERS_FLAG_RESET);
635634 pCtx->SetIndexBuffer(m_pIB, 0, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
636635 pCtx->SetPipelineState(m_pPSO);
637 pCtx->CommitShaderResources(m_pSRB, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
638636
639637 const float blend_factor[4] = {0.f, 0.f, 0.f, 0.f};
640638 pCtx->SetBlendFactors(blend_factor);
655653
656654 // Render command lists
657655 // (Because we merged all buffers into a single one, we maintain our own offset into them)
658 int global_idx_offset = 0;
659 int global_vtx_offset = 0;
656 int global_idx_offset = 0;
657 int global_vtx_offset = 0;
658 ITextureView* pLastTextureView = nullptr;
660659
661660 for (int n = 0; n < pDrawData->CmdListsCount; n++)
662661 {
698697 static_cast<Uint32>(m_RenderSurfaceWidth * pDrawData->FramebufferScale.x),
699698 static_cast<Uint32>(m_RenderSurfaceHeight * pDrawData->FramebufferScale.y));
700699
701 // Bind texture, Draw
702 auto* texture_srv = reinterpret_cast<ITextureView*>(pcmd->TextureId);
703 VERIFY_EXPR(texture_srv == m_pFontSRV);
704 (void)texture_srv;
705 //ctx->PSSetShaderResources(0, 1, &texture_srv);
700 // Bind texture
701 auto pTextureView = reinterpret_cast<ITextureView*>(pcmd->TextureId);
702 VERIFY_EXPR(pTextureView);
703 if (pTextureView != pLastTextureView)
704 {
705 pLastTextureView = pTextureView;
706 m_pSRB->GetVariableByName(SHADER_TYPE_PIXEL, "Texture")->Set(pTextureView);
707 pCtx->CommitShaderResources(m_pSRB, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
708 }
709
710 // Draw
706711 DrawIndexedAttribs DrawAttrs(pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? VT_UINT16 : VT_UINT32, DRAW_FLAG_VERIFY_STATES);
707712 DrawAttrs.FirstIndexLocation = pcmd->IdxOffset + global_idx_offset;
708713 DrawAttrs.BaseVertex = pcmd->VtxOffset + global_vtx_offset;