def retraceApi(self, api):
print '''
-static IDirect3DDevice9 *
-pLastDirect3DDevice9 = NULL;
-image::Image *
-retrace::getSnapshot(void) {
- if (!pLastDirect3DDevice9) {
- return NULL;
+class D3D9Dumper : public retrace::Dumper {
+public:
+ IDirect3DDevice9 *pLastDirect3DDevice9;
+
+ D3D9Dumper() :
+ pLastDirect3DDevice9(NULL)
+ {}
+
+ image::Image *
+ getSnapshot(void) {
+ if (!pLastDirect3DDevice9) {
+ return NULL;
+ }
+ return d3dstate::getRenderTargetImage(pLastDirect3DDevice9);
}
- return d3dstate::getRenderTargetImage(pLastDirect3DDevice9);
-}
+ bool
+ dumpState(std::ostream &os) {
+ if (!pLastDirect3DDevice9) {
+ return false;
+ }
+ d3dstate::dumpDevice(os, pLastDirect3DDevice9);
+ return true;
+ }
-bool
-retrace::dumpState(std::ostream &os)
-{
- if (!pLastDirect3DDevice9) {
- return false;
+ inline void
+ bindDevice(IDirect3DDevice9 *pDevice) {
+ pLastDirect3DDevice9 = pDevice;
+ retrace::dumper = this;
}
- d3dstate::dumpDevice(os, pLastDirect3DDevice9);
- return true;
-}
+
+ inline void
+ unbindDevice(IDirect3DDevice9 *pDevice) {
+ if (pLastDirect3DDevice9 == pDevice) {
+ pLastDirect3DDevice9 = NULL;
+ }
+ }
+};
+
+static D3D9Dumper d3d9Dumper;
'''
print '// Swizzling mapping for lock addresses'
def invokeInterfaceMethod(self, interface, method):
# keep track of the last used device for state dumping
if interface.name in ('IDirect3DDevice9', 'IDirect3DDevice9Ex'):
- print r' pLastDirect3DDevice9 = _this;'
+ if method.name == 'Release':
+ print r' d3d9Dumper.unbindDevice(_this);'
+ else:
+ print r' d3d9Dumper.bindDevice(_this);'
# create windows as neccessary
if method.name in ('CreateDevice', 'CreateDeviceEx', 'CreateAdditionalSwapChain'):
} /* namespace glretrace */
+class GLDumper : public retrace::Dumper {
+public:
+ image::Image *
+ getSnapshot(void) {
+ if (!glretrace::getCurrentContext()) {
+ return NULL;
+ }
+ return glstate::getDrawBufferImage();
+ }
+
+ bool
+ dumpState(std::ostream &os) {
+ glretrace::Context *currentContext = glretrace::getCurrentContext();
+ if (glretrace::insideGlBeginEnd ||
+ !currentContext) {
+ return false;
+ }
+ glstate::dumpCurrentContext(os);
+ return true;
+ }
+};
+
+static GLDumper glDumper;
+
+
void
retrace::setUp(void) {
glws::init();
+ dumper = &glDumper;
}
}
-image::Image *
-retrace::getSnapshot(void) {
- if (!glretrace::getCurrentContext()) {
- return NULL;
- }
-
- return glstate::getDrawBufferImage();
-}
-
-
-bool
-retrace::dumpState(std::ostream &os)
-{
- glretrace::Context *currentContext = glretrace::getCurrentContext();
-
- if (glretrace::insideGlBeginEnd ||
- !currentContext) {
- return false;
- }
-
- glstate::dumpCurrentContext(os);
-
- return true;
-}
-
void
retrace::flushRendering(void) {
glretrace::Context *currentContext = glretrace::getCurrentContext();
}
+static Dumper defaultDumper;
+
+Dumper *dumper = &defaultDumper;
+
+
/**
* Take/compare snapshots.
*/
}
}
- image::Image *src = getSnapshot();
+ image::Image *src = dumper->getSnapshot();
if (!src) {
return;
}
takeSnapshot(call->no);
if (call->no >= dumpStateCallNo &&
- dumpState(std::cout)) {
+ dumper->dumpState(std::cout)) {
exit(0);
}
}