1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- // TestApp1.cpp : Defines the entry point for the application.
- //
-
- #ifdef _WIN32
- #include "Win32/stdafx.h"
- #endif
-
- #include <DK.h>
-
-
- class TestApp1 : public DKApplication
- {
- DKObject<DKWindow> window;
- DKObject<DKScreen> screen;
- public:
- void OnInitialize(void) override
- {
- DKLog("%s", DKGL_FUNCTION_NAME);
- try {
- window = DKWindow::Create("DefaultWindow");
- screen = DKOBJECT_NEW DKScreen(window, NULL);
- }
- catch (DKError& e)
- {
- DKLog("error? :%ls", (const wchar_t*)e.Description());
- }
- window->Activate();
-
- window->AddEventHandler(this,
- DKFunction([this](const DKWindow::WindowEvent& e) {
- if (e.type == DKWindow::WindowEvent::WindowClosed)
- DKApplication::Instance()->Terminate(0);
- }),
- NULL, NULL);
-
- DKObject<DKGraphicsDevice> device = DKGraphicsDevice::SharedInstance();
- DKObject<DKCommandQueue> queue = device->CreateCommandQueue();
- DKObject<DKCommandBuffer> buffer = queue->CreateCommandBuffer();
- DKObject<DKSwapChain> swapChain = queue->CreateSwapChain(window);
-
- }
- void OnTerminate(void) override
- {
- DKLog("%s", DKGL_FUNCTION_NAME);
- DKLog("Memory Pool Statistics");
- size_t numBuckets = DKMemoryPoolNumberOfBuckets();
- DKMemoryPoolBucketStatus* buckets = new DKMemoryPoolBucketStatus[numBuckets];
- DKMemoryPoolQueryAllocationStatus(buckets, numBuckets);
- size_t usedBytes = 0;
- for (int i = 0; i < numBuckets; ++i)
- {
- if (buckets[i].totalChunks > 0)
- {
- DKLog("--> %lu: %lu/%lu (usage:%.1f%%, used:%.1KB, total%.1fKB)",
- buckets[i].chunkSize,
- buckets[i].usedChunks, buckets[i].totalChunks,
- double(buckets[i].usedChunks) / double(buckets[i].totalChunks) * 100.0,
- double(buckets[i].chunkSize * buckets[i].usedChunks) / 1024.0,
- double(buckets[i].chunkSize * buckets[i].totalChunks) / 1024.0
- );
- usedBytes += buckets[i].chunkSize * buckets[i].usedChunks;
- }
- }
- DKLog("MemoryPool Usage: %.1fMB / %.1fMB", double(usedBytes) / (1024 * 1024), double(DKMemoryPoolSize()) / (1024 * 1024));
- delete[] buckets;
- }
- };
-
-
- #ifdef _WIN32
- int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
- _In_opt_ HINSTANCE hPrevInstance,
- _In_ LPWSTR lpCmdLine,
- _In_ int nCmdShow)
- #else
- int main(int argc, const char * argv[])
- #endif
- {
- TestApp1 app;
- DKPropertySet::SystemConfig().SetValue("AppDelegate", "AppDelegate");
- DKPropertySet::SystemConfig().SetValue("GraphicsAPI", "Vulkan");
- return app.Run();
- }
|