mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-08-11 01:01:05 +00:00
Expose GetTextureData function to user code (no resolving/downcasting)
This commit is contained in:
@@ -173,6 +173,7 @@ extern "C" RENDERDOC_API bool32 RENDERDOC_CC ReplayRenderer_GetMinMax(ReplayRend
|
||||
extern "C" RENDERDOC_API bool32 RENDERDOC_CC ReplayRenderer_GetHistogram(ReplayRenderer *rend, ResourceId tex, uint32_t sliceFace, uint32_t mip, uint32_t sample, float minval, float maxval, bool32 channels[4], rdctype::array<uint32_t> *histogram);
|
||||
|
||||
extern "C" RENDERDOC_API bool32 RENDERDOC_CC ReplayRenderer_GetBufferData(ReplayRenderer *rend, ResourceId buff, uint32_t offset, uint32_t len, rdctype::array<byte> *data);
|
||||
extern "C" RENDERDOC_API bool32 RENDERDOC_CC ReplayRenderer_GetTextureData(ReplayRenderer *rend, ResourceId tex, uint32_t arrayIdx, uint32_t mip, rdctype::array<byte> *data);
|
||||
|
||||
#ifdef RENDERDOC_EXPORTS
|
||||
struct RemoteAccess;
|
||||
|
||||
@@ -439,6 +439,21 @@ bool ReplayRenderer::GetBufferData(ResourceId buff, uint32_t offset, uint32_t le
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ReplayRenderer::GetTextureData(ResourceId tex, uint32_t arrayIdx, uint32_t mip, rdctype::array<byte> *data)
|
||||
{
|
||||
if(data == NULL) return false;
|
||||
|
||||
size_t sz;
|
||||
byte *bytes = m_pDevice->GetTextureData(m_pDevice->GetLiveID(tex), arrayIdx, mip, false, false, 0.0f, 0.0f, sz);
|
||||
|
||||
create_array_uninit(*data, sz);
|
||||
memcpy(data->elems, bytes, sz);
|
||||
|
||||
delete[] bytes;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ReplayRenderer::SaveTexture(const TextureSave &saveData, const char *path)
|
||||
{
|
||||
TextureSave sd = saveData; // mutable copy
|
||||
@@ -1576,3 +1591,6 @@ extern "C" RENDERDOC_API bool32 RENDERDOC_CC ReplayRenderer_GetHistogram(ReplayR
|
||||
|
||||
extern "C" RENDERDOC_API bool32 RENDERDOC_CC ReplayRenderer_GetBufferData(ReplayRenderer *rend, ResourceId buff, uint32_t offset, uint32_t len, rdctype::array<byte> *data)
|
||||
{ return rend->GetBufferData(buff, offset, len, data); }
|
||||
|
||||
extern "C" RENDERDOC_API bool32 RENDERDOC_CC ReplayRenderer_GetTextureData(ReplayRenderer *rend, ResourceId tex, uint32_t arrayIdx, uint32_t mip, rdctype::array<byte> *data)
|
||||
{ return rend->GetTextureData(tex, arrayIdx, mip, data); }
|
||||
|
||||
@@ -177,6 +177,7 @@ struct ReplayRenderer
|
||||
bool GetUsage(ResourceId id, rdctype::array<EventUsage> *usage);
|
||||
|
||||
bool GetBufferData(ResourceId buff, uint32_t offset, uint32_t len, rdctype::array<byte> *data);
|
||||
bool GetTextureData(ResourceId buff, uint32_t arrayIdx, uint32_t mip, rdctype::array<byte> *data);
|
||||
|
||||
bool SaveTexture(const TextureSave &saveData, const char *path);
|
||||
|
||||
|
||||
@@ -255,6 +255,8 @@ namespace renderdoc
|
||||
|
||||
[DllImport("renderdoc.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern bool ReplayRenderer_GetBufferData(IntPtr real, ResourceId buff, UInt32 offset, UInt32 len, IntPtr outdata);
|
||||
[DllImport("renderdoc.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern bool ReplayRenderer_GetTextureData(IntPtr real, ResourceId tex, UInt32 arrayIdx, UInt32 mip, IntPtr outdata);
|
||||
|
||||
private IntPtr m_Real = IntPtr.Zero;
|
||||
|
||||
@@ -791,6 +793,22 @@ namespace renderdoc
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public byte[] GetTextureData(ResourceId tex, UInt32 arrayIdx, UInt32 mip)
|
||||
{
|
||||
IntPtr mem = CustomMarshal.Alloc(typeof(templated_array));
|
||||
|
||||
bool success = ReplayRenderer_GetTextureData(m_Real, tex, arrayIdx, mip, mem);
|
||||
|
||||
byte[] ret = null;
|
||||
|
||||
if (success)
|
||||
ret = (byte[])CustomMarshal.GetTemplatedArray(mem, typeof(byte), true);
|
||||
|
||||
CustomMarshal.Free(mem);
|
||||
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
public class RemoteRenderer
|
||||
|
||||
Reference in New Issue
Block a user