No Description

TestApp1.cpp 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. public:
  11. void OnInitialize(void) override
  12. {
  13. DKLog("%s", DKGL_FUNCTION_NAME);
  14. window = DKWindow::Create("DefaultWindow");
  15. window->Activate();
  16. window->AddEventHandler(this,
  17. DKFunction([this](const DKWindow::WindowEvent& e) {
  18. if (e.type == DKWindow::WindowEvent::WindowClosed)
  19. DKApplication::Instance()->Terminate(0);
  20. }),
  21. NULL, NULL);
  22. DKObject<DKGraphicsDevice> device = DKGraphicsDevice::SharedInstance();
  23. DKObject<DKCommandQueue> queue = device->CreateCommandQueue();
  24. DKObject<DKCommandBuffer> buffer = queue->CreateCommandBuffer();
  25. }
  26. void OnTerminate(void) override
  27. {
  28. DKLog("%s", DKGL_FUNCTION_NAME);
  29. DKLog("Memory Pool Statistics");
  30. size_t numBuckets = DKMemoryPoolNumberOfBuckets();
  31. DKMemoryPoolBucketStatus* buckets = new DKMemoryPoolBucketStatus[numBuckets];
  32. DKMemoryPoolQueryAllocationStatus(buckets, numBuckets);
  33. size_t usedBytes = 0;
  34. for (int i = 0; i < numBuckets; ++i)
  35. {
  36. if (buckets[i].totalChunks > 0)
  37. {
  38. DKLog("--> %lu: allocated:%lu, reserved:%.1fKB. (usage:%.1f%%)",
  39. buckets[i].chunkSize,
  40. buckets[i].chunkSize * buckets[i].usedChunks,
  41. double(buckets[i].chunkSize * (buckets[i].totalChunks - buckets[i].usedChunks)) / 1024.0,
  42. double(buckets[i].usedChunks) / double(buckets[i].totalChunks) * 100.0);
  43. usedBytes += buckets[i].chunkSize * buckets[i].usedChunks;
  44. }
  45. }
  46. DKLog("MemoryPool Usage: %.1fMB / %.1fMB", double(usedBytes) / (1024 * 1024), double(DKMemoryPoolSize()) / (1024 * 1024));
  47. delete[] buckets;
  48. }
  49. };
  50. #ifdef _WIN32
  51. int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
  52. _In_opt_ HINSTANCE hPrevInstance,
  53. _In_ LPWSTR lpCmdLine,
  54. _In_ int nCmdShow)
  55. #else
  56. int main(int argc, const char * argv[])
  57. #endif
  58. {
  59. TestApp1 app;
  60. DKPropertySet::SystemConfig().SetValue("AppDelegate", "AppDelegate");
  61. return app.Run();
  62. }