forked from baldurk/renderdoc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisplay_window.py
More file actions
118 lines (84 loc) · 3.06 KB
/
Copy pathdisplay_window.py
File metadata and controls
118 lines (84 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import renderdoc as rd
def loadCapture(filename):
# Open a capture file handle
cap = rd.OpenCaptureFile()
# Open a particular file - see also OpenBuffer to load from memory
status = cap.OpenFile(filename, '', None)
# Make sure the file opened successfully
if status != rd.ReplayStatus.Succeeded:
raise RuntimeError("Couldn't open file: " + str(status))
# Make sure we can replay
if not cap.LocalReplaySupport():
raise RuntimeError("Capture cannot be replayed")
# Initialise the replay
status,controller = cap.OpenCapture(None)
if status != rd.ReplayStatus.Succeeded:
raise RuntimeError("Couldn't initialise replay: " + str(status))
return controller
if 'pyrenderdoc' in globals():
raise RuntimeError("This sample should not be run within the RenderDoc UI")
else:
controller = loadCapture('test.rdc')
# Use tkinter to create windows
import tkinter
# Create a simple window
window = tkinter.Tk()
window.geometry("1280x720")
# Create renderdoc windowing data.
winsystems = [rd.WindowingSystem(i) for i in controller.GetSupportedWindowSystems()]
# Pass window system specific data here, See:
# - renderdoc.CreateWin32WindowingData
# - renderdoc.CreateXlibWindowingData
# - renderdoc.CreateXCBWindowingData
# This example code works on windows as that's simple to integrate with tkinter
if not rd.WindowingSystem.Win32 in winsystems:
raise RuntimeError("Example requires Win32 windowing system: " + str(winsystems))
windata = rd.CreateWin32WindowingData(int(window.frame(), 16))
# Create a texture output on the window
out = controller.CreateOutput(windata, rd.ReplayOutputType.Texture)
# Fetch the list of textures
textures = controller.GetTextures()
# Fetch the list of drawcalls
draws = controller.GetDrawcalls()
# Function to look up the texture descriptor for a given resourceId
def getTexture(texid):
global textures
for tex in textures:
if tex.resourceId == texid:
return tex
return None
# Our paint function will be called ever 33ms, to display the output
def paint():
global out, window
out.Display()
window.after(33, paint)
# Start on the first drawcall
curdraw = 0
# The advance function will be called every 150ms, to move to the next draw
def advance():
global out, window, curdraw
# Move to the current drawcall
controller.SetFrameEvent(draws[curdraw].eventId, False)
# Initialise a default TextureDisplay object
disp = rd.TextureDisplay()
# Set the first colour output as the texture to display
disp.resourceId = draws[curdraw].outputs[0]
# Get the details of this texture
texDetails = getTexture(disp.resourceId)
# Calculate the scale required in width and height
widthScale = window.winfo_width() / texDetails.width
heightScale = window.winfo_height() / texDetails.height
# Use the lower scale to fit the texture on the window
disp.scale = min(widthScale, heightScale)
# Update the texture display
out.SetTextureDisplay(disp)
# Set the next drawcall
curdraw = (curdraw + 1) % len(draws)
window.after(150, advance)
# Start the callbacks
advance()
paint()
# Start the main window loop
window.mainloop()
controller.Shutdown()
cap.Shutdown()