1 ##########################################################################
3 # Copyright 2011 Jose Fonseca
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 ##########################################################################/
27 """GL retracer generator."""
30 import specs.stdapi as stdapi
31 from specs.d3d9 import d3d9
32 from retrace import Retracer
35 class D3DRetracer(Retracer):
37 table_name = 'd3dretrace::d3d9_callbacks'
39 def invokeInterfaceMethod(self, interface, method):
40 if interface.name == 'IDirect3D9' and method.name == 'CreateDevice':
41 print 'HWND hWnd = createWindow(pPresentationParameters->BackBufferWidth, pPresentationParameters->BackBufferHeight);'
42 print 'pPresentationParameters->hDeviceWindow = hWnd;'
43 print 'hFocusWindow = hWnd;'
45 Retracer.invokeInterfaceMethod(self, interface, method)
47 if str(method.type) == 'HRESULT':
48 print r' if (__result != S_OK) {'
49 print r' retrace::warning(call) << "failed\n";'
52 if interface.name == 'IDirect3DVertexBuffer9' and method.name == 'Lock':
53 print ' if (!SizeToLock) {'
54 print ' D3DVERTEXBUFFER_DESC Desc;'
55 print ' _this->GetDesc(&Desc);'
56 print ' SizeToLock = Desc.Size;'
60 if __name__ == '__main__':
66 #include "d3d9imports.hpp"
67 #include "d3dretrace.hpp"
70 // XXX: Don't duplicate this code.
72 static LRESULT CALLBACK
73 WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
77 case WM_GETMINMAXINFO:
78 // Allow to create a window bigger than the desktop
79 pMMI = (MINMAXINFO *)lParam;
80 pMMI->ptMaxSize.x = 60000;
81 pMMI->ptMaxSize.y = 60000;
82 pMMI->ptMaxTrackSize.x = 60000;
83 pMMI->ptMaxTrackSize.y = 60000;
89 return DefWindowProc(hWnd, uMsg, wParam, lParam);
94 createWindow(int width, int height) {
95 static bool first = TRUE;
100 memset(&wc, 0, sizeof wc);
101 wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
102 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
103 wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
104 wc.lpfnWndProc = WndProc;
105 wc.lpszClassName = "d3dretrace";
106 wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
116 dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW;
122 rect.right = rect.left + width;
123 rect.bottom = rect.top + height;
125 AdjustWindowRectEx(&rect, dwStyle, FALSE, dwExStyle);
127 hWnd = CreateWindowEx(dwExStyle,
128 "d3dretrace", /* wc.lpszClassName */
133 rect.right - rect.left, /* width */
134 rect.bottom - rect.top, /* height */
139 ShowWindow(hWnd, SW_SHOW);
144 retracer = D3DRetracer()
145 retracer.retraceApi(d3d9)