Bez popisu

TestApp1.cpp 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // TestApp1.cpp : Defines the entry point for the application.
  2. //
  3. #ifdef _WIN32
  4. #include "Win32/stdafx.h"
  5. #endif
  6. #include <DK.h>
  7. class TestApp1 : public DKApplication
  8. {
  9. DKObject<DKWindow> window;
  10. DKObject<DKScreen> screen;
  11. public:
  12. void OnInitialize(void) override
  13. {
  14. DKLog("%s", DKGL_FUNCTION_NAME);
  15. try {
  16. window = DKWindow::Create("DefaultWindow");
  17. screen = DKOBJECT_NEW DKScreen(window, NULL);
  18. }
  19. catch (DKError& e)
  20. {
  21. DKLog("error? :%ls", (const wchar_t*)e.Description());
  22. }
  23. window->Activate();
  24. window->AddEventHandler(this,
  25. DKFunction([this](const DKWindow::WindowEvent& e) {
  26. if (e.type == DKWindow::WindowEvent::WindowClosed)
  27. DKApplication::Instance()->Terminate(0);
  28. }),
  29. NULL, NULL);
  30. DKObject<DKGraphicsDevice> device = DKGraphicsDevice::SharedInstance();
  31. DKObject<DKCommandQueue> queue = device->CreateCommandQueue();
  32. DKObject<DKCommandBuffer> buffer = queue->CreateCommandBuffer();
  33. DKObject<DKSwapChain> swapChain = queue->CreateSwapChain(window);
  34. }
  35. void OnTerminate(void) override
  36. {
  37. DKLog("%s", DKGL_FUNCTION_NAME);
  38. DKLog("Memory Pool Statistics");
  39. size_t numBuckets = DKMemoryPoolNumberOfBuckets();
  40. DKMemoryPoolBucketStatus* buckets = new DKMemoryPoolBucketStatus[numBuckets];
  41. DKMemoryPoolQueryAllocationStatus(buckets, numBuckets);
  42. size_t usedBytes = 0;
  43. for (int i = 0; i < numBuckets; ++i)
  44. {
  45. if (buckets[i].totalChunks > 0)
  46. {
  47. DKLog("--> %lu: %lu/%lu (usage:%.1f%%, used:%.1KB, total%.1fKB)",
  48. buckets[i].chunkSize,
  49. buckets[i].usedChunks, buckets[i].totalChunks,
  50. double(buckets[i].usedChunks) / double(buckets[i].totalChunks) * 100.0,
  51. double(buckets[i].chunkSize * buckets[i].usedChunks) / 1024.0,
  52. double(buckets[i].chunkSize * buckets[i].totalChunks) / 1024.0
  53. );
  54. usedBytes += buckets[i].chunkSize * buckets[i].usedChunks;
  55. }
  56. }
  57. DKLog("MemoryPool Usage: %.1fMB / %.1fMB", double(usedBytes) / (1024 * 1024), double(DKMemoryPoolSize()) / (1024 * 1024));
  58. delete[] buckets;
  59. }
  60. };
  61. #ifdef _WIN32
  62. int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
  63. _In_opt_ HINSTANCE hPrevInstance,
  64. _In_ LPWSTR lpCmdLine,
  65. _In_ int nCmdShow)
  66. #else
  67. int main(int argc, const char * argv[])
  68. #endif
  69. {
  70. TestApp1 app;
  71. DKPropertySet::SystemConfig().SetValue("AppDelegate", "AppDelegate");
  72. DKPropertySet::SystemConfig().SetValue("GraphicsAPI", "Vulkan");
  73. return app.Run();
  74. }