MCPcopy Create free account
hub / github.com/baldurk/renderdoc / sampleCode

Function sampleCode

docs/python_api/examples/renderdoc/save_texture.py:24–74  ·  view source on GitHub ↗
(controller)

Source from the content-addressed store, hash-verified

22 return ret
23
24def sampleCode(controller):
25 # Find the biggest drawcall in the whole capture
26 draw = None
27 for d in controller.GetRootActions():
28 draw = biggestDraw(draw, d)
29
30 # Move to that draw
31 controller.SetFrameEvent(draw.eventId, True)
32
33 texsave = rd.TextureSave()
34
35 # Select the first color output
36 texsave.resourceId = draw.outputs[0]
37
38 if texsave.resourceId == rd.ResourceId.Null():
39 return
40
41 filename = str(int(texsave.resourceId))
42
43 print("Saving images of %s at %d: %s" % (filename, draw.eventId, draw.GetName(controller.GetStructuredFile())))
44
45 # Save different types of texture
46
47 # Blend alpha to a checkerboard pattern for formats without alpha support
48 texsave.alpha = rd.AlphaMapping.BlendToCheckerboard
49
50 # Most formats can only display a single image per file, so we select the
51 # first mip and first slice
52 texsave.mip = 0
53 texsave.slice.sliceIndex = 0
54
55 texsave.destType = rd.FileType.JPG
56 controller.SaveTexture(texsave, filename + ".jpg")
57
58 texsave.destType = rd.FileType.HDR
59 controller.SaveTexture(texsave, filename + ".hdr")
60
61 # For formats with an alpha channel, preserve it
62 texsave.alpha = rd.AlphaMapping.Preserve
63
64 texsave.destType = rd.FileType.PNG
65 controller.SaveTexture(texsave, filename + ".png")
66
67 # DDS textures can save multiple mips and array slices, so instead
68 # of the default behaviour of saving mip 0 and slice 0, we set -1
69 # which saves *all* mips and slices
70 texsave.mip = -1
71 texsave.slice.sliceIndex = -1
72
73 texsave.destType = rd.FileType.DDS
74 controller.SaveTexture(texsave, filename + ".dds")
75
76def loadCapture(filename):
77 # Open a capture file handle

Callers 1

save_texture.pyFile · 0.70

Calls 7

intFunction · 0.85
printFunction · 0.85
SaveTextureMethod · 0.80
biggestDrawFunction · 0.70
SetFrameEventMethod · 0.45
GetNameMethod · 0.45
GetStructuredFileMethod · 0.45

Tested by

no test coverage detected