Browse Source

setup render-thread

Hongtae Kim 7 years ago
parent
commit
b49be0876a
1 changed files with 32 additions and 8 deletions
  1. 32
    8
      TestApp1/TestApp1.cpp

+ 32
- 8
TestApp1/TestApp1.cpp View File

@@ -11,14 +11,35 @@
11 11
 class TestApp1 : public DKApplication
12 12
 {
13 13
 	DKObject<DKWindow> window;
14
-	DKObject<DKScreen> screen;
14
+	DKObject<DKThread> renderThread;
15
+
16
+	DKAtomicNumber32 runningRenderThread;
15 17
 public:
18
+	void RenderThread(void)
19
+	{
20
+		DKObject<DKGraphicsDevice> device = DKGraphicsDevice::SharedInstance();
21
+		DKObject<DKCommandQueue> queue = device->CreateCommandQueue();
22
+		DKObject<DKCommandBuffer> buffer = queue->CreateCommandBuffer();
23
+		DKObject<DKSwapChain> swapChain = queue->CreateSwapChain(window);
24
+
25
+		DKTimer timer;
26
+		timer.Reset();
27
+
28
+		DKLog("Render thread begin");
29
+		while (!runningRenderThread.CompareAndSet(0, 0))
30
+		{
31
+
32
+
33
+			DKThread::Sleep(0.01);
34
+		}
35
+		DKLog("RenderThread terminating...");
36
+	}
37
+
16 38
 	void OnInitialize(void) override
17 39
 	{
18 40
 		DKLog("%s", DKGL_FUNCTION_NAME);
19 41
 		try {
20 42
 			window = DKWindow::Create("DefaultWindow");
21
-			screen = DKOBJECT_NEW DKScreen(window, NULL);
22 43
 		}
23 44
 		catch (DKError& e)
24 45
 		{
@@ -31,17 +52,20 @@ public:
31 52
 			if (e.type == DKWindow::WindowEvent::WindowClosed)
32 53
 				DKApplication::Instance()->Terminate(0);
33 54
 		}),
34
-			NULL, NULL);
35
-
36
-		DKObject<DKGraphicsDevice> device = DKGraphicsDevice::SharedInstance();
37
-		DKObject<DKCommandQueue> queue = device->CreateCommandQueue();
38
-		DKObject<DKCommandBuffer> buffer = queue->CreateCommandBuffer();
39
-		DKObject<DKSwapChain> swapChain = queue->CreateSwapChain(window);
55
+		NULL, NULL);
40 56
 
57
+		runningRenderThread = 1;
58
+		renderThread = DKThread::Create(DKFunction(this, &TestApp1::RenderThread)->Invocation());
41 59
 	}
42 60
 	void OnTerminate(void) override
43 61
 	{
44 62
 		DKLog("%s", DKGL_FUNCTION_NAME);
63
+
64
+		runningRenderThread = 0;
65
+		renderThread->WaitTerminate();
66
+		renderThread = NULL;
67
+		window = NULL;
68
+
45 69
 		DKLog("Memory Pool Statistics");
46 70
 		size_t numBuckets = DKMemoryPoolNumberOfBuckets();
47 71
 		DKMemoryPoolBucketStatus* buckets = new DKMemoryPoolBucketStatus[numBuckets];