Heedong Lee před 4 roky
rodič
revize
3eebdfdeda
1 změnil soubory, kde provedl 68 přidání a 68 odebrání
  1. 68
    68
      Samples/DKGLDemoScene/DKGLDemoScene.cpp

+ 68
- 68
Samples/DKGLDemoScene/DKGLDemoScene.cpp Zobrazit soubor

@@ -14,9 +14,9 @@ struct SceneUniformBuffer
14 14
 class DKGLDemo : public SampleApp
15 15
 {
16 16
     DKObject<DKWindow> window;
17
-	DKObject<DKThread> renderThread;
18
-	DKAtomicNumber32 runningRenderThread;
19
-	DKObject<StaticMesh> sampleMesh;
17
+    DKObject<DKThread> renderThread;
18
+    DKAtomicNumber32 runningRenderThread;
19
+    DKObject<StaticMesh> sampleMesh;
20 20
 
21 21
     DKObject<DKGpuBuffer> sceneUniformBuffer;
22 22
     SceneUniformBuffer* sceneBufferData = nullptr;
@@ -36,15 +36,15 @@ public:
36 36
         sampleMesh->LoadTextureFromFile(resourcePool, texturePath);
37 37
     }
38 38
 
39
-	void LoadRenderResource(DKObject<DKCommandQueue> queue)
40
-	{
41
-		DKLog("Loading Static Meshes");
39
+    void LoadRenderResource(DKObject<DKCommandQueue> queue)
40
+    {
41
+        DKLog("Loading Static Meshes");
42 42
         DKString path = resourcePool.ResourceFilePath("meshes/VikingRoom/viking_room.obj");
43 43
         sampleMesh->LoadMeshResourceFromFile(queue->Device(), resourcePool, path);
44 44
         sampleMesh->LoadRenderResourceShader(queue->Device(), DKShaderStage::Vertex);
45 45
         sampleMesh->LoadRenderResourceShader(queue->Device(), DKShaderStage::Fragment);
46 46
         sampleMesh->LoadRenderResourceTexture(queue);
47
-	}
47
+    }
48 48
 
49 49
     void SetupPipeline(DKRenderPipelineDescriptor& pipelineDesc)
50 50
     {
@@ -82,16 +82,16 @@ public:
82 82
         sampleMesh->EncodeRenderCommand(encoder);
83 83
     }
84 84
 
85
-	void RenderThread(void)
86
-	{
87
-		DKObject<DKGraphicsDevice> device = DKGraphicsDevice::SharedInstance();
85
+    void RenderThread(void)
86
+    {
87
+        DKObject<DKGraphicsDevice> device = DKGraphicsDevice::SharedInstance();
88 88
         DKObject<DKCommandQueue> queue = device->CreateCommandQueue(DKCommandQueue::Graphics);
89 89
 
90 90
         LoadRenderResource(queue);
91 91
 
92
-		DKObject<DKSwapChain> swapChain = queue->CreateSwapChain(window);
92
+        DKObject<DKSwapChain> swapChain = queue->CreateSwapChain(window);
93 93
 
94
-		DKRenderPipelineDescriptor pipelineDescriptor;
94
+        DKRenderPipelineDescriptor pipelineDescriptor;
95 95
         // setup color-attachment render-targets
96 96
         pipelineDescriptor.colorAttachments.Resize(1);
97 97
         pipelineDescriptor.colorAttachments.Value(0).pixelFormat = swapChain->ColorPixelFormat();
@@ -112,12 +112,12 @@ public:
112 112
 
113 113
         SetupPipeline(pipelineDescriptor);
114 114
 
115
-		DKPipelineReflection reflection;
116
-		DKObject<DKRenderPipelineState> pipelineState = device->CreateRenderPipeline(pipelineDescriptor, &reflection);
117
-		if (pipelineState)
118
-		{
115
+        DKPipelineReflection reflection;
116
+        DKObject<DKRenderPipelineState> pipelineState = device->CreateRenderPipeline(pipelineDescriptor, &reflection);
117
+        if (pipelineState)
118
+        {
119 119
             PrintPipelineReflection(&reflection, DKLogCategory::Verbose);
120
-		}
120
+        }
121 121
 
122 122
         SetupMaterial(device);
123 123
         SetupSceneUniformBuffer(device);
@@ -128,25 +128,25 @@ public:
128 128
         DKVector3 cameraPosition = { 0, 5, 10 };
129 129
         DKVector3 cameraTartget = { 0, 0, 0 };
130 130
 
131
-        DKAffineTransform3 tm(DKLinearTransform3().Scale(5).Rotate(DKVector3(-1,0,0), DKGL_PI * 0.5));
131
+        DKAffineTransform3 tm(DKLinearTransform3().Scale(5).Rotate(DKVector3(-1, 0, 0), DKGL_PI * 0.5));
132 132
 
133 133
         DKTimer timer;
134
-		timer.Reset();
134
+        timer.Reset();
135 135
 
136
-		DKLog("Render thread begin");
137
-		while (!runningRenderThread.CompareAndSet(0, 0))
138
-		{
139
-			DKRenderPassDescriptor rpd = swapChain->CurrentRenderPassDescriptor();
140
-			double t = timer.Elapsed();
141
-			double waveT = (cos(t) + 1.0) * 0.5;
142
-			rpd.colorAttachments.Value(0).clearColor = DKColor(waveT, 0.0, 0.0, 0.0);
136
+        DKLog("Render thread begin");
137
+        while (!runningRenderThread.CompareAndSet(0, 0))
138
+        {
139
+            DKRenderPassDescriptor rpd = swapChain->CurrentRenderPassDescriptor();
140
+            double t = timer.Elapsed();
141
+            double waveT = (cos(t) + 1.0) * 0.5;
142
+            rpd.colorAttachments.Value(0).clearColor = DKColor(waveT, 0.0, 0.0, 0.0);
143 143
 
144 144
             int width = rpd.colorAttachments.Value(0).renderTarget->Width();
145 145
             int height = rpd.colorAttachments.Value(0).renderTarget->Height();
146 146
             if (depthBuffer)
147 147
             {
148
-                if (depthBuffer->Width() !=  width ||
149
-                    depthBuffer->Height() != height )
148
+                if (depthBuffer->Width() != width ||
149
+                    depthBuffer->Height() != height)
150 150
                     depthBuffer = nullptr;
151 151
             }
152 152
             if (depthBuffer == nullptr)
@@ -168,14 +168,14 @@ public:
168 168
             rpd.depthStencilAttachment.loadAction = DKRenderPassAttachmentDescriptor::LoadActionClear;
169 169
             rpd.depthStencilAttachment.storeAction = DKRenderPassAttachmentDescriptor::StoreActionDontCare;
170 170
 
171
-			DKObject<DKCommandBuffer> buffer = queue->CreateCommandBuffer();
172
-			DKObject<DKRenderCommandEncoder> encoder = buffer->CreateRenderCommandEncoder(rpd);
173
-			if (encoder)
174
-			{
171
+            DKObject<DKCommandBuffer> buffer = queue->CreateCommandBuffer();
172
+            DKObject<DKRenderCommandEncoder> encoder = buffer->CreateRenderCommandEncoder(rpd);
173
+            if (encoder)
174
+            {
175 175
                 if (sceneUniformBuffer)
176 176
                 {
177 177
                     camera.SetView(cameraPosition, cameraTartget - cameraPosition, DKVector3(0, 1, 0));
178
-                    camera.SetPerspective(DKGL_DEGREE_TO_RADIAN(90), float(width)/float(height), 1, 1000);
178
+                    camera.SetPerspective(DKGL_DEGREE_TO_RADIAN(90), float(width) / float(height), 1, 1000);
179 179
 
180 180
                     sceneBufferData->projectionMatrix = camera.ProjectionMatrix();
181 181
                     sceneBufferData->viewMatrix = camera.ViewMatrix();
@@ -188,25 +188,25 @@ public:
188 188
                     sampleMesh->SetupExternalUniformBuffer(sceneUniformBuffer, sizeof(SceneUniformBuffer), 0);
189 189
                 }
190 190
 
191
-				encoder->SetRenderPipelineState(pipelineState);
191
+                encoder->SetRenderPipelineState(pipelineState);
192 192
 
193 193
                 EncodeScene(encoder);
194 194
 
195 195
                 buffer->Commit();
196
-				swapChain->Present();
197
-			}
198
-			else
199
-			{
200
-			}
201
-			DKThread::Sleep(0.01);
202
-		}
203
-		DKLog("RenderThread terminating...");
204
-	}
205
-
206
-	void OnInitialize(void) override
207
-	{
196
+                swapChain->Present();
197
+            }
198
+            else
199
+            {
200
+            }
201
+            DKThread::Sleep(0.01);
202
+        }
203
+        DKLog("RenderThread terminating...");
204
+    }
205
+
206
+    void OnInitialize(void) override
207
+    {
208 208
         SampleApp::OnInitialize();
209
-		DKLogD("%s", DKGL_FUNCTION_NAME);
209
+        DKLogD("%s", DKGL_FUNCTION_NAME);
210 210
 
211 211
         // create window
212 212
         window = DKWindow::Create("DefaultWindow");
@@ -215,42 +215,42 @@ public:
215 215
         window->Activate();
216 216
 
217 217
         window->AddEventHandler(this, DKFunction([this](const DKWindow::WindowEvent& e)
218
-        {
219
-            if (e.type == DKWindow::WindowEvent::WindowClosed)
220
-                DKApplication::Instance()->Terminate(0);
221
-        }), NULL, NULL);
218
+            {
219
+                if (e.type == DKWindow::WindowEvent::WindowClosed)
220
+                    DKApplication::Instance()->Terminate(0);
221
+            }), NULL, NULL);
222 222
 
223 223
         sampleMesh = DKObject<StaticMesh>::New();
224 224
         LoadResource();
225 225
 
226
-		runningRenderThread = 1;
227
-		renderThread = DKThread::Create(DKFunction(this, &DKGLDemo::RenderThread)->Invocation());
228
-	}
229
-	void OnTerminate(void) override
230
-	{
231
-		DKLogD("%s", DKGL_FUNCTION_NAME);
226
+        runningRenderThread = 1;
227
+        renderThread = DKThread::Create(DKFunction(this, &DKGLDemo::RenderThread)->Invocation());
228
+    }
229
+    void OnTerminate(void) override
230
+    {
231
+        DKLogD("%s", DKGL_FUNCTION_NAME);
232 232
 
233
-		runningRenderThread = 0;
234
-		renderThread->WaitTerminate();
235
-		renderThread = NULL;
233
+        runningRenderThread = 0;
234
+        renderThread->WaitTerminate();
235
+        renderThread = NULL;
236 236
         window = NULL;
237 237
 
238 238
         SampleApp::OnTerminate();
239
-	}
239
+    }
240 240
 };
241 241
 
242 242
 
243 243
 #ifdef _WIN32
244 244
 int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
245
-					  _In_opt_ HINSTANCE hPrevInstance,
246
-					  _In_ LPWSTR    lpCmdLine,
247
-					  _In_ int       nCmdShow)
245
+    _In_opt_ HINSTANCE hPrevInstance,
246
+    _In_ LPWSTR    lpCmdLine,
247
+    _In_ int       nCmdShow)
248 248
 #else
249
-int main(int argc, const char * argv[])
249
+int main(int argc, const char* argv[])
250 250
 #endif
251 251
 {
252 252
     DKGLDemo app;
253
-	DKPropertySet::SystemConfig().SetValue("AppDelegate", "AppDelegate");
254
-	DKPropertySet::SystemConfig().SetValue("GraphicsAPI", "Vulkan");
255
-	return app.Run();
253
+    DKPropertySet::SystemConfig().SetValue("AppDelegate", "AppDelegate");
254
+    DKPropertySet::SystemConfig().SetValue("GraphicsAPI", "Vulkan");
255
+    return app.Run();
256 256
 }