private static void RunSample(DXSample sample) { Console.WriteLine($"Running: {sample.Name}"); var exitCode = Run(sample); Console.WriteLine($" Completed with exit code: {exitCode}"); }
public static int Run(DXSample sample, HINSTANCE hInstance, int nCmdShow) { var useWarpDevice = false; // Parse the command line parameters foreach (var arg in Environment.GetCommandLineArgs()) { if (Program.Matches(arg, "warp")) { useWarpDevice = true; continue; } } fixed(char *lpszClassName = "DXSampleClass") fixed(char *lpWindowName = sample.Name) { // Initialize the window class. var windowClass = new WNDCLASSEXW { cbSize = (uint)sizeof(WNDCLASSEXW), style = CS_HREDRAW | CS_VREDRAW, lpfnWndProc = &WindowProc, hInstance = hInstance, hCursor = LoadCursorW(HINSTANCE.NULL, (ushort *)IDC_ARROW), lpszClassName = (ushort *)lpszClassName }; _ = RegisterClassExW(&windowClass); // Create the window and store a handle to it. s_hwnd = CreateWindowExW( 0, windowClass.lpszClassName, (ushort *)lpWindowName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, HWND.NULL, // We have no parent window. HMENU.NULL, // We aren't using menus. hInstance, ((IntPtr)GCHandle.Alloc(sample)).ToPointer() ); } RECT windowRect; _ = GetClientRect(s_hwnd, &windowRect); // Initialize the sample. OnInit is defined in each child-implementation of DXSample. var backgroundColor = new Vector4(0.0f, 0.2f, 0.4f, 1.0f); var size = new Size(windowRect.right - windowRect.left, windowRect.bottom - windowRect.top); sample.OnInit(DXGI_FORMAT_UNKNOWN, backgroundColor, DXGI_FORMAT_UNKNOWN, 1.0f, 2, s_hwnd, true, size, useWarpDevice); _ = ShowWindow(s_hwnd, nCmdShow); // Main sample loop. MSG msg; DispatchPending(&msg); var lastFramesPerSecond = 0u; while (msg.message != WM_QUIT) { var delta = sample.OnBeginFrame(); sample.OnUpdate(delta); var framesPerSecond = sample.FramesPerSecond; if (framesPerSecond != lastFramesPerSecond) { fixed(char *lpWindowName = $"{sample.Name} ({framesPerSecond} fps)") { _ = SetWindowTextW(s_hwnd, (ushort *)lpWindowName); } lastFramesPerSecond = framesPerSecond; } if (sample.IsWindowVisible) { sample.OnRender(); } DispatchPending(&msg); } sample.OnDestroy(); // Return this part of the WM_QUIT message to Windows. return((int)msg.wParam);
private static int Run(DXSample sample) { var hInstance = GetModuleHandleW(null); return(Win32Application.Run(sample, hInstance, SW_SHOWDEFAULT)); }