Browse Source

1. shader/texture 쉐이더 테스트.

2. 파이프라인만 테스트하고 종료. (쓰레드 생성 안함)
Hongtae Kim 5 years ago
parent
commit
5f92d62b5e
1 changed files with 30 additions and 98 deletions
  1. 30
    98
      TestApp1/TestApp1.cpp

+ 30
- 98
TestApp1/TestApp1.cpp View File

@@ -172,16 +172,36 @@ void PrintShaderResource(const DKShaderResource& res)
172 172
 
173 173
 class TestApp1 : public DKApplication
174 174
 {
175
-	DKObject<DKWindow> window;
176
-	DKObject<DKThread> renderThread;
177 175
 	DKResourcePool resourcePool;
178
-
179
-	DKAtomicNumber32 runningRenderThread;
180 176
 public:
181
-	void RenderThread(void)
177
+	void OnInitialize(void) override
182 178
 	{
183
-		DKObject<DKData> vertData = resourcePool.LoadResourceData("shaders/triangle/triangle.vert.spv");
184
-		DKObject<DKData> fragData = resourcePool.LoadResourceData("shaders/triangle/triangle.frag.spv");
179
+		DKLogD("%s", DKGL_FUNCTION_NAME);
180
+
181
+		DKString resPath = DefaultPath(SystemPath::AppResource);
182
+		resPath = resPath.FilePathStringByAppendingPath("Data");
183
+		DKLog("resPath: %ls", (const wchar_t*)resPath);
184
+		resourcePool.AddLocatorForPath(resPath);
185
+
186
+		DKObject<DKData> vertData = resourcePool.LoadResourceData("shaders/texture/texture.vert.spv");
187
+		DKObject<DKData> fragData = resourcePool.LoadResourceData("shaders/texture/texture.frag.spv");
188
+
189
+		struct Vertex
190
+		{
191
+			DKVector3 position;
192
+			DKVector2 uv;
193
+			DKVector3 normal;
194
+		};
195
+		DKVertexDescriptor vertexDescriptor;
196
+		vertexDescriptor.attributes = {
197
+			{ DKVertexFormat::Float3, 0, 0, 0 },
198
+			{ DKVertexFormat::Float2, sizeof(DKVector2), 0, 1 },
199
+			{ DKVertexFormat::Float3, sizeof(DKVector3), 0, 2 },
200
+		};
201
+		vertexDescriptor.layouts = {
202
+			{ DKVertexStepRate::Vertex, sizeof(Vertex), 0 },
203
+		};
204
+
185 205
 		DKShader vertShader(vertData, DKShader::Vertex);
186 206
 		DKShader fragShader(fragData, DKShader::Fragment);
187 207
 
@@ -193,7 +213,6 @@ public:
193 213
 		DKObject<DKShaderFunction> fragShaderFunction = fragShaderModule->CreateFunction(fragShaderModule->FunctionNames().Value(0));
194 214
 
195 215
 		DKObject<DKCommandQueue> queue = device->CreateCommandQueue(DKCommandQueue::Graphics);
196
-		DKObject<DKSwapChain> swapChain = queue->CreateSwapChain(window);
197 216
 
198 217
 		DKLog("VertexFunction.VertexAttributes: %d", vertShaderFunction->VertexAttributes().Count());
199 218
 		for (int i = 0; i < vertShaderFunction->VertexAttributes().Count(); ++i)
@@ -202,42 +221,13 @@ public:
202 221
 			DKLog("  --> VertexAttribute[%d]: \"%ls\" (location:%u)", i, (const wchar_t*)attr.name, attr.location);
203 222
 		}
204 223
 
205
-		struct Vertex
206
-		{
207
-			DKVector3 position;
208
-			DKVector3 color;
209
-		};
210
-		DKArray<Vertex> vertexData =
211
-		{
212
-			{ {  0.0f, -0.5f, 0.0f },{ 1.0f, 1.0f, 1.0f } },
213
-			{ {  0.5f,  0.5f, 0.0f },{ 0.0f, 1.0f, 0.0f } },
214
-			{ { -0.5f,  0.5f, 0.0f },{ 0.0f, 0.0f, 1.0f } }
215
-		};
216
-		uint32_t vertexBufferSize = static_cast<uint32_t>(vertexData.Count()) * sizeof(Vertex);
217
-		DKArray<uint32_t> indexData = { 0, 1, 2 };
218
-		uint32_t indexBufferSize = indexData.Count() * sizeof(uint32_t);
219
-
220
-		DKObject<DKGpuBuffer> vertexBuffer = device->CreateBuffer(vertexBufferSize, DKGpuBuffer::StorageModeShared, DKCpuCacheModeDefault);
221
-		memcpy(vertexBuffer->Lock(), vertexData, vertexBufferSize);
222
-		vertexBuffer->Unlock();
223
-
224
-		DKObject<DKGpuBuffer> indexBuffer = device->CreateBuffer(indexBufferSize, DKGpuBuffer::StorageModeShared, DKCpuCacheModeDefault);
225
-		memcpy(indexBuffer->Lock(), indexData, indexBufferSize);
226
-		indexBuffer->Unlock();
227
-
228 224
 		DKRenderPipelineDescriptor pipelineDescriptor;
229 225
 		pipelineDescriptor.vertexFunction = vertShaderFunction;
230 226
 		pipelineDescriptor.fragmentFunction = fragShaderFunction;
231 227
 		pipelineDescriptor.colorAttachments.Resize(1);
232
-		pipelineDescriptor.colorAttachments.Value(0).pixelFormat = swapChain->ColorPixelFormat();
228
+		pipelineDescriptor.colorAttachments.Value(0).pixelFormat = DKPixelFormat::RGBA8Unorm;
233 229
 		pipelineDescriptor.depthStencilAttachmentPixelFormat = DKPixelFormat::Invalid; // no depth buffer
234
-		pipelineDescriptor.vertexDescriptor.attributes = {
235
-			{ DKVertexFormat::Float3, 0, 0, 0 },
236
-			{ DKVertexFormat::Float3, sizeof(DKVector3), 0, 1 },
237
-		};
238
-		pipelineDescriptor.vertexDescriptor.layouts = {
239
-			{ DKVertexStepRate::Vertex, sizeof(Vertex), 0 },
240
-		};
230
+		pipelineDescriptor.vertexDescriptor = vertexDescriptor;
241 231
 		pipelineDescriptor.primitiveTopology = DKPrimitiveType::Triangle;
242 232
 		pipelineDescriptor.frontFace = DKFrontFace::CCW;
243 233
 		pipelineDescriptor.triangleFillMode = DKTriangleFillMode::Fill;
@@ -257,70 +247,12 @@ public:
257 247
 				PrintShaderResource(arg);
258 248
 		}
259 249
 
260
-		DKTimer timer;
261
-		timer.Reset();
262
-
263
-		DKLog("Render thread begin");
264
-		while (!runningRenderThread.CompareAndSet(0, 0))
265
-		{
266
-			DKRenderPassDescriptor rpd = swapChain->CurrentRenderPassDescriptor();
267
-			double t = timer.Elapsed();
268
-			t = (cos(t) + 1.0) * 0.5;
269
-			rpd.colorAttachments.Value(0).clearColor = DKColor(t, 0.0, 0.0, 0.0);
270
-
271
-			DKObject<DKCommandBuffer> buffer = queue->CreateCommandBuffer();
272
-			DKObject<DKRenderCommandEncoder> encoder = buffer->CreateRenderCommandEncoder(rpd);
273
-			if (encoder)
274
-			{
275
-				encoder->SetRenderPipelineState(pipelineState);
276
-				encoder->SetVertexBuffer(vertexBuffer, 0, 0);
277
-				encoder->SetIndexBuffer(indexBuffer, 0, DKIndexType::UInt32);
278
-				// draw scene!
279
-				encoder->DrawIndexed(indexData.Count(), 1, 0, 0, 1);
280
-				encoder->EndEncoding();
281
-				buffer->Commit();
282
-				swapChain->Present();
283
-			}
284
-			else
285
-			{
286
-			}
287
-			DKThread::Sleep(0.01);
288
-		}
289
-		DKLog("RenderThread terminating...");
290
-	}
291
-
292
-	void OnInitialize(void) override
293
-	{
294
-		DKLogD("%s", DKGL_FUNCTION_NAME);
295
-
296
-		DKString resPath = DefaultPath(SystemPath::AppResource);
297
-		resPath = resPath.FilePathStringByAppendingPath("Data");
298
-		DKLog("resPath: %ls", (const wchar_t*)resPath);
299
-		resourcePool.AddLocatorForPath(resPath);
300
-
301
-		window = DKWindow::Create("DefaultWindow");
302
-		window->SetOrigin({ 0, 0 });
303
-		window->Resize({ 320, 240 });
304
-		window->Activate();
305
-
306
-		window->AddEventHandler(this, DKFunction([this](const DKWindow::WindowEvent& e)
307
-		{
308
-			if (e.type == DKWindow::WindowEvent::WindowClosed)
309
-				DKApplication::Instance()->Terminate(0);
310
-		}), NULL, NULL);
311
-
312
-		runningRenderThread = 1;
313
-		renderThread = DKThread::Create(DKFunction(this, &TestApp1::RenderThread)->Invocation());
250
+		Terminate(0);
314 251
 	}
315 252
 	void OnTerminate(void) override
316 253
 	{
317 254
 		DKLogD("%s", DKGL_FUNCTION_NAME);
318 255
 
319
-		runningRenderThread = 0;
320
-		renderThread->WaitTerminate();
321
-		renderThread = NULL;
322
-		window = NULL;
323
-
324 256
 		DKLogI("Memory Pool Statistics");
325 257
 		size_t numBuckets = DKMemoryPoolNumberOfBuckets();
326 258
 		DKMemoryPoolBucketStatus* buckets = new DKMemoryPoolBucketStatus[numBuckets];