From f01dfbecc1cf5031ef13ecb56994c4d63faf1ab5 Mon Sep 17 00:00:00 2001 From: baldurk Date: Tue, 31 May 2022 11:26:59 +0100 Subject: [PATCH] Add a python extension function to access picked location. Refs #2065 --- qrenderdoc/Code/Interface/QRDInterface.h | 9 +++++++++ qrenderdoc/Windows/TextureViewer.cpp | 25 ++++++++++++++++++++++++ qrenderdoc/Windows/TextureViewer.h | 1 + 3 files changed, 35 insertions(+) diff --git a/qrenderdoc/Code/Interface/QRDInterface.h b/qrenderdoc/Code/Interface/QRDInterface.h index 855030bec..8183274f1 100644 --- a/qrenderdoc/Code/Interface/QRDInterface.h +++ b/qrenderdoc/Code/Interface/QRDInterface.h @@ -667,6 +667,15 @@ bounds parameters will be clamped to the available subresources. )"); virtual void GotoLocation(uint32_t x, uint32_t y) = 0; + DOCUMENT(R"(Returns the currently selected texel location in the current texture. + +If no location is currently selected or there is no current texture, this will return ``(-1, -1)``. + +:return: The currently picked pixel location. +:rtype: Tuple[int,int] +)"); + virtual rdcpair GetPickedLocation() = 0; + DOCUMENT(R"(Return the currently selected texture overlay. :return: The currently selected texture overlay. diff --git a/qrenderdoc/Windows/TextureViewer.cpp b/qrenderdoc/Windows/TextureViewer.cpp index a73d6854c..6e4984fb3 100644 --- a/qrenderdoc/Windows/TextureViewer.cpp +++ b/qrenderdoc/Windows/TextureViewer.cpp @@ -1815,6 +1815,7 @@ void TextureViewer::UI_UpdateChannels() INVOKE_MEMFN(RT_UpdateAndDisplay); INVOKE_MEMFN(RT_UpdateVisualRange); + UI_UpdateStatusText(); } void TextureViewer::SetupTextureTabs() @@ -3791,6 +3792,30 @@ void TextureViewer::on_locationGoto_clicked() ShowGotoPopup(); } +rdcpair TextureViewer::GetPickedLocation() +{ + TextureDescription *texptr = GetCurrentTexture(); + + if(texptr) + { + QPoint p = m_PickedPoint; + + p.setX(p.x() >> (int)m_TexDisplay.subresource.mip); + p.setY(p.y() >> (int)m_TexDisplay.subresource.mip); + + uint32_t mipHeight = qMax(1U, texptr->height >> (int)m_TexDisplay.subresource.mip); + + if(ShouldFlipForGL()) + p.setY((int)(mipHeight - 1) - p.y()); + if(m_TexDisplay.flipY) + p.setY((int)(mipHeight - 1) - p.y()); + + return {p.x(), p.y()}; + } + + return {-1, -1}; +} + void TextureViewer::ShowGotoPopup() { TextureDescription *texptr = GetCurrentTexture(); diff --git a/qrenderdoc/Windows/TextureViewer.h b/qrenderdoc/Windows/TextureViewer.h index 212d2f08a..2a5a93d75 100644 --- a/qrenderdoc/Windows/TextureViewer.h +++ b/qrenderdoc/Windows/TextureViewer.h @@ -143,6 +143,7 @@ public: Subresource GetSelectedSubresource() override; void SetSelectedSubresource(Subresource sub) override; + rdcpair GetPickedLocation() override; void GotoLocation(uint32_t x, uint32_t y) override; DebugOverlay GetTextureOverlay() override; void SetTextureOverlay(DebugOverlay overlay) override;