Browse Source

setup render-thread

Hongtae Kim 8 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
 class TestApp1 : public DKApplication
11
 class TestApp1 : public DKApplication
12
 {
12
 {
13
 	DKObject<DKWindow> window;
13
 	DKObject<DKWindow> window;
14
-	DKObject<DKScreen> screen;
14
+	DKObject<DKThread> renderThread;
15
+
16
+	DKAtomicNumber32 runningRenderThread;
15
 public:
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
 	void OnInitialize(void) override
38
 	void OnInitialize(void) override
17
 	{
39
 	{
18
 		DKLog("%s", DKGL_FUNCTION_NAME);
40
 		DKLog("%s", DKGL_FUNCTION_NAME);
19
 		try {
41
 		try {
20
 			window = DKWindow::Create("DefaultWindow");
42
 			window = DKWindow::Create("DefaultWindow");
21
-			screen = DKOBJECT_NEW DKScreen(window, NULL);
22
 		}
43
 		}
23
 		catch (DKError& e)
44
 		catch (DKError& e)
24
 		{
45
 		{
31
 			if (e.type == DKWindow::WindowEvent::WindowClosed)
52
 			if (e.type == DKWindow::WindowEvent::WindowClosed)
32
 				DKApplication::Instance()->Terminate(0);
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
 	void OnTerminate(void) override
60
 	void OnTerminate(void) override
43
 	{
61
 	{
44
 		DKLog("%s", DKGL_FUNCTION_NAME);
62
 		DKLog("%s", DKGL_FUNCTION_NAME);
63
+
64
+		runningRenderThread = 0;
65
+		renderThread->WaitTerminate();
66
+		renderThread = NULL;
67
+		window = NULL;
68
+
45
 		DKLog("Memory Pool Statistics");
69
 		DKLog("Memory Pool Statistics");
46
 		size_t numBuckets = DKMemoryPoolNumberOfBuckets();
70
 		size_t numBuckets = DKMemoryPoolNumberOfBuckets();
47
 		DKMemoryPoolBucketStatus* buckets = new DKMemoryPoolBucketStatus[numBuckets];
71
 		DKMemoryPoolBucketStatus* buckets = new DKMemoryPoolBucketStatus[numBuckets];