Skip to content

Commit

Permalink
Add a python extension function to access picked location. Refs #2065
Browse files Browse the repository at this point in the history
  • Loading branch information
baldurk committed May 31, 2022
1 parent 6d7d482 commit f01dfbe
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
9 changes: 9 additions & 0 deletions qrenderdoc/Code/Interface/QRDInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int32_t, int32_t> GetPickedLocation() = 0;

DOCUMENT(R"(Return the currently selected texture overlay.
:return: The currently selected texture overlay.
Expand Down
25 changes: 25 additions & 0 deletions qrenderdoc/Windows/TextureViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1815,6 +1815,7 @@ void TextureViewer::UI_UpdateChannels()

INVOKE_MEMFN(RT_UpdateAndDisplay);
INVOKE_MEMFN(RT_UpdateVisualRange);
UI_UpdateStatusText();
}

void TextureViewer::SetupTextureTabs()
Expand Down Expand Up @@ -3791,6 +3792,30 @@ void TextureViewer::on_locationGoto_clicked()
ShowGotoPopup();
}

rdcpair<int32_t, int32_t> 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();
Expand Down
1 change: 1 addition & 0 deletions qrenderdoc/Windows/TextureViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class TextureViewer : public QFrame, public ITextureViewer, public ICaptureViewe

Subresource GetSelectedSubresource() override;
void SetSelectedSubresource(Subresource sub) override;
rdcpair<int32_t, int32_t> GetPickedLocation() override;
void GotoLocation(uint32_t x, uint32_t y) override;
DebugOverlay GetTextureOverlay() override;
void SetTextureOverlay(DebugOverlay overlay) override;
Expand Down

0 comments on commit f01dfbe

Please sign in to comment.