mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-08-23 06:56:40 +00:00
Fix float precision/rounding issues for NPOT textures. Closes #2807
This commit is contained in:
@@ -4455,7 +4455,10 @@ uint32_t TextureViewer::MipCoordFromBase(int coord, uint32_t dim)
|
||||
|
||||
float coordf = float(coord) / float(dim);
|
||||
|
||||
return uint32_t(mipDim * coordf);
|
||||
// we add 1e-6 to account for float errors, where we might not get back coord after rounding down
|
||||
// in the coordf calculation even when mipDim == dim. This will not affect the rounding for any
|
||||
// realistic texture sizes - even for a dim of 16383 and coord of 16382
|
||||
return uint32_t(mipDim * coordf + 1e-6);
|
||||
}
|
||||
|
||||
uint32_t TextureViewer::BaseCoordFromMip(int coord, uint32_t dim)
|
||||
@@ -4467,7 +4470,7 @@ uint32_t TextureViewer::BaseCoordFromMip(int coord, uint32_t dim)
|
||||
|
||||
float coordf = float(coord) / float(mipDim);
|
||||
|
||||
return uint32_t(dim * coordf);
|
||||
return uint32_t(dim * coordf + 1e-6);
|
||||
}
|
||||
|
||||
void TextureViewer::on_customCreate_clicked()
|
||||
|
||||
@@ -729,11 +729,11 @@ void ReplayOutput::DisplayContext()
|
||||
rdcpair<uint32_t, uint32_t> mipDim = {RDCMAX(1U, m_TextureDim.first >> disp.subresource.mip),
|
||||
RDCMAX(1U, m_TextureDim.second >> disp.subresource.mip)};
|
||||
|
||||
x = int((float(x) / float(m_TextureDim.first)) * mipDim.first);
|
||||
x = int((float(x) / float(mipDim.first)) * m_TextureDim.first);
|
||||
x = int((float(x) / float(m_TextureDim.first)) * mipDim.first + 1e-6f);
|
||||
x = int((float(x) / float(mipDim.first)) * m_TextureDim.first + 1e-6f);
|
||||
|
||||
y = int((float(y) / float(m_TextureDim.second)) * mipDim.second);
|
||||
y = int((float(y) / float(mipDim.second)) * m_TextureDim.second);
|
||||
y = int((float(y) / float(m_TextureDim.second)) * mipDim.second + 1e-6f);
|
||||
y = int((float(y) / float(mipDim.second)) * m_TextureDim.second + 1e-6f);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user