Sfoglia il codice sorgente

fix : mesh project update with recent api

Heedong Lee 3 anni fa
parent
commit
d0b064da7f
1 ha cambiato i file con 16 aggiunte e 16 eliminazioni
  1. 16
    16
      Samples/Mesh/Mesh.cpp

+ 16
- 16
Samples/Mesh/Mesh.cpp Vedi File

49
 		}
49
 		}
50
 	};
50
 	};
51
 
51
 
52
-	SampleObjMesh() 
52
+	SampleObjMesh()
53
 	{
53
 	{
54
 		vertices.Reserve(100);
54
 		vertices.Reserve(100);
55
 		indices.Reserve(100);
55
 		indices.Reserve(100);
64
 		if (!tinyobj::LoadObj(&attrib, &shapes, &materials, &err, InPath)) {
64
 		if (!tinyobj::LoadObj(&attrib, &shapes, &materials, &err, InPath)) {
65
 			throw std::runtime_error(err);
65
 			throw std::runtime_error(err);
66
 		}
66
 		}
67
-		
67
+
68
 		DKMap<Vertex, uint32_t> uniqueVertices;
68
 		DKMap<Vertex, uint32_t> uniqueVertices;
69
 		DKLog("Save to Container");
69
 		DKLog("Save to Container");
70
 		for (const auto& shape : shapes)
70
 		for (const auto& shape : shapes)
85
 					attrib.texcoords[2 * index.texcoord_index + 0],
85
 					attrib.texcoords[2 * index.texcoord_index + 0],
86
 					1.0f - attrib.texcoords[2 * index.texcoord_index + 1]
86
 					1.0f - attrib.texcoords[2 * index.texcoord_index + 1]
87
 					};
87
 					};
88
-				}				
88
+				}
89
 
89
 
90
 				vertex.inColor = { 1.0f, 1.0f, 1.0f };
90
 				vertex.inColor = { 1.0f, 1.0f, 1.0f };
91
 
91
 
102
 		}
102
 		}
103
 	}
103
 	}
104
 
104
 
105
-	uint32_t GetVerticesCount() const { 
105
+	uint32_t GetVerticesCount() const {
106
 		return static_cast<uint32_t>(vertices.Count()); };
106
 		return static_cast<uint32_t>(vertices.Count()); };
107
-	uint32_t GetIndicesCount() const { 
107
+	uint32_t GetIndicesCount() const {
108
 		return static_cast<uint32_t>(indices.Count()); };
108
 		return static_cast<uint32_t>(indices.Count()); };
109
-	const Vertex* GetVerticesData() const { 
109
+	const Vertex* GetVerticesData() const {
110
 		return vertices; }
110
 		return vertices; }
111
-	const uint32_t* GetIndicesData() const { 
111
+	const uint32_t* GetIndicesData() const {
112
 		return indices; }
112
 		return indices; }
113
 
113
 
114
     DKAabb aabb;
114
     DKAabb aabb;
138
 public:
138
 public:
139
 	void LoadMesh()
139
 	void LoadMesh()
140
 	{
140
 	{
141
-		
141
+
142
 		DKLog("Loading Mesh");
142
 		DKLog("Loading Mesh");
143
         DKString path = resourcePool.ResourceFilePath("meshes/chalet.obj");
143
         DKString path = resourcePool.ResourceFilePath("meshes/chalet.obj");
144
 		SampleMesh->LoadFromObjFile(DKStringU8(path));
144
 		SampleMesh->LoadFromObjFile(DKStringU8(path));
171
 
171
 
172
                 size_t bufferLength = bytesPerPixel * width * height;
172
                 size_t bufferLength = bytesPerPixel * width * height;
173
                 DKObject<DKGpuBuffer> stagingBuffer = device->CreateBuffer(bufferLength, DKGpuBuffer::StorageModeShared, DKCpuCacheModeReadWrite);
173
                 DKObject<DKGpuBuffer> stagingBuffer = device->CreateBuffer(bufferLength, DKGpuBuffer::StorageModeShared, DKCpuCacheModeReadWrite);
174
-                
174
+
175
                 memcpy(stagingBuffer->Contents(), image->Contents(), bufferLength);
175
                 memcpy(stagingBuffer->Contents(), image->Contents(), bufferLength);
176
                 stagingBuffer->Flush();
176
                 stagingBuffer->Flush();
177
 
177
 
211
 		samplerDesc.addressModeV = DKSamplerDescriptor::AddressModeClampToEdge;
211
 		samplerDesc.addressModeV = DKSamplerDescriptor::AddressModeClampToEdge;
212
 		samplerDesc.addressModeW = DKSamplerDescriptor::AddressModeClampToEdge;
212
 		samplerDesc.addressModeW = DKSamplerDescriptor::AddressModeClampToEdge;
213
 		samplerDesc.maxAnisotropy = 16;
213
 		samplerDesc.maxAnisotropy = 16;
214
-		
214
+
215
 		DKObject<DKSamplerState> sampler = device->CreateSamplerState(samplerDesc);
215
 		DKObject<DKSamplerState> sampler = device->CreateSamplerState(samplerDesc);
216
 
216
 
217
         // create shaders
217
         // create shaders
230
 			DKLog("  --> VertexAttribute[%d]: \"%ls\" (location:%u)", i, (const wchar_t*)attr.name, attr.location);
230
 			DKLog("  --> VertexAttribute[%d]: \"%ls\" (location:%u)", i, (const wchar_t*)attr.name, attr.location);
231
 		}
231
 		}
232
 
232
 
233
-	
233
+
234
 		uint32_t vertexBufferSize = static_cast<uint32_t>(SampleMesh->GetVerticesCount()) * sizeof(SampleObjMesh::Vertex);
234
 		uint32_t vertexBufferSize = static_cast<uint32_t>(SampleMesh->GetVerticesCount()) * sizeof(SampleObjMesh::Vertex);
235
 		uint32_t indexBufferSize = SampleMesh->GetIndicesCount() * sizeof(uint32_t);
235
 		uint32_t indexBufferSize = SampleMesh->GetIndicesCount() * sizeof(uint32_t);
236
 
236
 
249
         // setup color-attachment render-targets
249
         // setup color-attachment render-targets
250
 		pipelineDescriptor.colorAttachments.Resize(1);
250
 		pipelineDescriptor.colorAttachments.Resize(1);
251
 		pipelineDescriptor.colorAttachments.Value(0).pixelFormat = swapChain->ColorPixelFormat();
251
 		pipelineDescriptor.colorAttachments.Value(0).pixelFormat = swapChain->ColorPixelFormat();
252
-        pipelineDescriptor.colorAttachments.Value(0).blendingEnabled = false;
253
-        pipelineDescriptor.colorAttachments.Value(0).sourceRGBBlendFactor = DKBlendFactor::SourceAlpha;
254
-        pipelineDescriptor.colorAttachments.Value(0).destinationRGBBlendFactor = DKBlendFactor::OneMinusSourceAlpha;
252
+        pipelineDescriptor.colorAttachments.Value(0).blendState.enabled = false;
253
+        pipelineDescriptor.colorAttachments.Value(0).blendState.sourceRGBBlendFactor = DKBlendFactor::SourceAlpha;
254
+        pipelineDescriptor.colorAttachments.Value(0).blendState.destinationRGBBlendFactor = DKBlendFactor::OneMinusSourceAlpha;
255
         // setup depth-stencil
255
         // setup depth-stencil
256
 		pipelineDescriptor.depthStencilAttachmentPixelFormat = DKPixelFormat::D32Float;
256
 		pipelineDescriptor.depthStencilAttachmentPixelFormat = DKPixelFormat::D32Float;
257
         pipelineDescriptor.depthStencilDescriptor.depthWriteEnabled = true;
257
         pipelineDescriptor.depthStencilDescriptor.depthWriteEnabled = true;
326
                 //memcpy(uboBuffer->Contents(), &ubo, sizeof(ubo));
326
                 //memcpy(uboBuffer->Contents(), &ubo, sizeof(ubo));
327
                 bindSet->SetBuffer(0, uboBuffer, 0, sizeof(UBO));
327
                 bindSet->SetBuffer(0, uboBuffer, 0, sizeof(UBO));
328
             }
328
             }
329
-			         
329
+
330
             bindSet->SetTexture(1, texture);
330
             bindSet->SetTexture(1, texture);
331
             bindSet->SetSamplerState(1, sampler);
331
             bindSet->SetSamplerState(1, sampler);
332
         }
332
         }
336
         DKCamera camera;
336
         DKCamera camera;
337
         DKVector3 cameraPosition = { 0, 5, 10 };
337
         DKVector3 cameraPosition = { 0, 5, 10 };
338
         DKVector3 cameraTartget = { 0, 0, 0 };
338
         DKVector3 cameraTartget = { 0, 0, 0 };
339
-		
339
+
340
         DKAffineTransform3 tm(DKLinearTransform3().Scale(5).Rotate(DKVector3(-1,0,0), DKGL_PI * 0.5));
340
         DKAffineTransform3 tm(DKLinearTransform3().Scale(5).Rotate(DKVector3(-1,0,0), DKGL_PI * 0.5));
341
 
341
 
342
         DKTimer timer;
342
         DKTimer timer;