浏览代码

fix : respacing

Heedong Lee 4 年前
父节点
当前提交
3eebdfdeda
共有 1 个文件被更改,包括 68 次插入68 次删除
  1. 68
    68
      Samples/DKGLDemoScene/DKGLDemoScene.cpp

+ 68
- 68
Samples/DKGLDemoScene/DKGLDemoScene.cpp 查看文件

14
 class DKGLDemo : public SampleApp
14
 class DKGLDemo : public SampleApp
15
 {
15
 {
16
     DKObject<DKWindow> window;
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
     DKObject<DKGpuBuffer> sceneUniformBuffer;
21
     DKObject<DKGpuBuffer> sceneUniformBuffer;
22
     SceneUniformBuffer* sceneBufferData = nullptr;
22
     SceneUniformBuffer* sceneBufferData = nullptr;
36
         sampleMesh->LoadTextureFromFile(resourcePool, texturePath);
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
         DKString path = resourcePool.ResourceFilePath("meshes/VikingRoom/viking_room.obj");
42
         DKString path = resourcePool.ResourceFilePath("meshes/VikingRoom/viking_room.obj");
43
         sampleMesh->LoadMeshResourceFromFile(queue->Device(), resourcePool, path);
43
         sampleMesh->LoadMeshResourceFromFile(queue->Device(), resourcePool, path);
44
         sampleMesh->LoadRenderResourceShader(queue->Device(), DKShaderStage::Vertex);
44
         sampleMesh->LoadRenderResourceShader(queue->Device(), DKShaderStage::Vertex);
45
         sampleMesh->LoadRenderResourceShader(queue->Device(), DKShaderStage::Fragment);
45
         sampleMesh->LoadRenderResourceShader(queue->Device(), DKShaderStage::Fragment);
46
         sampleMesh->LoadRenderResourceTexture(queue);
46
         sampleMesh->LoadRenderResourceTexture(queue);
47
-	}
47
+    }
48
 
48
 
49
     void SetupPipeline(DKRenderPipelineDescriptor& pipelineDesc)
49
     void SetupPipeline(DKRenderPipelineDescriptor& pipelineDesc)
50
     {
50
     {
82
         sampleMesh->EncodeRenderCommand(encoder);
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
         DKObject<DKCommandQueue> queue = device->CreateCommandQueue(DKCommandQueue::Graphics);
88
         DKObject<DKCommandQueue> queue = device->CreateCommandQueue(DKCommandQueue::Graphics);
89
 
89
 
90
         LoadRenderResource(queue);
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
         // setup color-attachment render-targets
95
         // setup color-attachment render-targets
96
         pipelineDescriptor.colorAttachments.Resize(1);
96
         pipelineDescriptor.colorAttachments.Resize(1);
97
         pipelineDescriptor.colorAttachments.Value(0).pixelFormat = swapChain->ColorPixelFormat();
97
         pipelineDescriptor.colorAttachments.Value(0).pixelFormat = swapChain->ColorPixelFormat();
112
 
112
 
113
         SetupPipeline(pipelineDescriptor);
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
             PrintPipelineReflection(&reflection, DKLogCategory::Verbose);
119
             PrintPipelineReflection(&reflection, DKLogCategory::Verbose);
120
-		}
120
+        }
121
 
121
 
122
         SetupMaterial(device);
122
         SetupMaterial(device);
123
         SetupSceneUniformBuffer(device);
123
         SetupSceneUniformBuffer(device);
128
         DKVector3 cameraPosition = { 0, 5, 10 };
128
         DKVector3 cameraPosition = { 0, 5, 10 };
129
         DKVector3 cameraTartget = { 0, 0, 0 };
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
         DKTimer timer;
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
             int width = rpd.colorAttachments.Value(0).renderTarget->Width();
144
             int width = rpd.colorAttachments.Value(0).renderTarget->Width();
145
             int height = rpd.colorAttachments.Value(0).renderTarget->Height();
145
             int height = rpd.colorAttachments.Value(0).renderTarget->Height();
146
             if (depthBuffer)
146
             if (depthBuffer)
147
             {
147
             {
148
-                if (depthBuffer->Width() !=  width ||
149
-                    depthBuffer->Height() != height )
148
+                if (depthBuffer->Width() != width ||
149
+                    depthBuffer->Height() != height)
150
                     depthBuffer = nullptr;
150
                     depthBuffer = nullptr;
151
             }
151
             }
152
             if (depthBuffer == nullptr)
152
             if (depthBuffer == nullptr)
168
             rpd.depthStencilAttachment.loadAction = DKRenderPassAttachmentDescriptor::LoadActionClear;
168
             rpd.depthStencilAttachment.loadAction = DKRenderPassAttachmentDescriptor::LoadActionClear;
169
             rpd.depthStencilAttachment.storeAction = DKRenderPassAttachmentDescriptor::StoreActionDontCare;
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
                 if (sceneUniformBuffer)
175
                 if (sceneUniformBuffer)
176
                 {
176
                 {
177
                     camera.SetView(cameraPosition, cameraTartget - cameraPosition, DKVector3(0, 1, 0));
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
                     sceneBufferData->projectionMatrix = camera.ProjectionMatrix();
180
                     sceneBufferData->projectionMatrix = camera.ProjectionMatrix();
181
                     sceneBufferData->viewMatrix = camera.ViewMatrix();
181
                     sceneBufferData->viewMatrix = camera.ViewMatrix();
188
                     sampleMesh->SetupExternalUniformBuffer(sceneUniformBuffer, sizeof(SceneUniformBuffer), 0);
188
                     sampleMesh->SetupExternalUniformBuffer(sceneUniformBuffer, sizeof(SceneUniformBuffer), 0);
189
                 }
189
                 }
190
 
190
 
191
-				encoder->SetRenderPipelineState(pipelineState);
191
+                encoder->SetRenderPipelineState(pipelineState);
192
 
192
 
193
                 EncodeScene(encoder);
193
                 EncodeScene(encoder);
194
 
194
 
195
                 buffer->Commit();
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
         SampleApp::OnInitialize();
208
         SampleApp::OnInitialize();
209
-		DKLogD("%s", DKGL_FUNCTION_NAME);
209
+        DKLogD("%s", DKGL_FUNCTION_NAME);
210
 
210
 
211
         // create window
211
         // create window
212
         window = DKWindow::Create("DefaultWindow");
212
         window = DKWindow::Create("DefaultWindow");
215
         window->Activate();
215
         window->Activate();
216
 
216
 
217
         window->AddEventHandler(this, DKFunction([this](const DKWindow::WindowEvent& e)
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
         sampleMesh = DKObject<StaticMesh>::New();
223
         sampleMesh = DKObject<StaticMesh>::New();
224
         LoadResource();
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
         window = NULL;
236
         window = NULL;
237
 
237
 
238
         SampleApp::OnTerminate();
238
         SampleApp::OnTerminate();
239
-	}
239
+    }
240
 };
240
 };
241
 
241
 
242
 
242
 
243
 #ifdef _WIN32
243
 #ifdef _WIN32
244
 int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
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
 #else
248
 #else
249
-int main(int argc, const char * argv[])
249
+int main(int argc, const char* argv[])
250
 #endif
250
 #endif
251
 {
251
 {
252
     DKGLDemo app;
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
 }