Hongtae Kim 5 anni fa
parent
commit
2ea8d13b3f

+ 3
- 0
Samples.xcworkspace/contents.xcworkspacedata Vedi File

@@ -5,6 +5,9 @@
5 5
       location = "container:"
6 6
       name = "Samples">
7 7
       <FileRef
8
+         location = "group:Samples/Mesh/Mesh.xcodeproj">
9
+      </FileRef>
10
+      <FileRef
8 11
          location = "group:Samples/Texture/Texture.xcodeproj">
9 12
       </FileRef>
10 13
       <FileRef

+ 23
- 13
Samples/Mesh/Mesh.cpp Vedi File

@@ -18,16 +18,24 @@ public:
18 18
 
19 19
 		int Compare(const Vertex& Other) const
20 20
 		{
21
-
22
-			if ( this == &Other 
23
-				|| inPos == Other.inPos && inColor == Other.inColor && intexCoord == Other.intexCoord)
24
-			{
25
-				return 0;
26
-			}
27
-			else
28
-			{
29
-				return static_cast<int>(this - &Other);
30
-			}
21
+            const float pp[] = { this->inPos.x, this->inPos.y, this->inPos.z,
22
+                this->inColor.x, this->inColor.y, this->inColor.z,
23
+                this->intexCoord.x, this->intexCoord.y};
24
+            const float rr[] = { Other.inPos.x, Other.inPos.y, Other.inPos.z,
25
+                Other.inColor.x, Other.inColor.y, Other.inColor.z,
26
+                Other.intexCoord.x, Other.intexCoord.y};
27
+
28
+            for (int i = 0; i < std::size(pp); ++i)
29
+            {
30
+                auto k = pp[i] - rr[i];
31
+                if (abs(k) < 0.0001)
32
+                    continue;
33
+                if (k > 0)
34
+                    return 1;
35
+                else if (k < 0)
36
+                    return -1;
37
+            }
38
+            return 0;
31 39
 		}
32 40
 
33 41
 		bool operator > (const Vertex& Other) const
@@ -132,7 +140,7 @@ public:
132 140
 	{
133 141
 		
134 142
 		DKLog("Loading Mesh");
135
-        DKString path = resourcePool.ResourceFilePath("meshes/car.obj");
143
+        DKString path = resourcePool.ResourceFilePath("meshes/chalet.obj");
136 144
 		SampleMesh->LoadFromObjFile(DKStringU8(path));
137 145
 	}
138 146
 
@@ -156,6 +164,8 @@ public:
156 164
             if (tex)
157 165
             {
158 166
                 size_t bytesPerPixel = image->BytesPerPixel();
167
+                DKASSERT_DESC(bytesPerPixel == DKPixelFormatBytesPerPixel(texDesc.pixelFormat), "BytesPerPixel mismatch!");
168
+
159 169
                 uint32_t width = image->Width();
160 170
                 uint32_t height = image->Height();
161 171
 
@@ -192,7 +202,7 @@ public:
192 202
         DKObject<DKCommandQueue> queue = device->CreateCommandQueue(DKCommandQueue::Graphics);
193 203
 
194 204
 		// create texture
195
-		DKObject<DKTexture> texture = LoadTexture2D(queue, resourcePool.LoadResourceData("textures/koo.jpg"));
205
+		DKObject<DKTexture> texture = LoadTexture2D(queue, resourcePool.LoadResourceData("meshes/chalet.png"));
196 206
 		// create sampler
197 207
 		DKSamplerDescriptor samplerDesc = {};
198 208
 		samplerDesc.magFilter = DKSamplerDescriptor::MinMagFilterLinear;
@@ -300,7 +310,7 @@ public:
300 310
                 ubo.viewMatrix = DKMatrix4::identity;
301 311
 
302 312
                 DKAffineTransform3 trans;
303
-                trans.Multiply(DKLinearTransform3().Scale(0.25).Rotate(DKVector3(1,1,1), DKGL_PI * 0.1));
313
+                trans.Multiply(DKLinearTransform3().Scale(0.25).Rotate(DKVector3(1,1,1), DKGL_PI * 0.25));
304 314
                 ubo.modelMatrix.Multiply(trans.Matrix4());
305 315
 
306 316
                 memcpy(uboBuffer->Contents(), &ubo, sizeof(ubo));

+ 35
- 28
Samples/Mesh/Mesh.xcodeproj/project.pbxproj Vedi File

@@ -7,8 +7,8 @@
7 7
 	objects = {
8 8
 
9 9
 /* Begin PBXBuildFile section */
10
-		66DA89941DD3117F00338015 /* Texture.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 844A9A801DD0C080007DCC89 /* Texture.cpp */; };
11
-		66DA89971DD3118000338015 /* Texture.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 844A9A801DD0C080007DCC89 /* Texture.cpp */; };
10
+		66DA89941DD3117F00338015 /* Mesh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 844A9A801DD0C080007DCC89 /* Mesh.cpp */; };
11
+		66DA89971DD3118000338015 /* Mesh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 844A9A801DD0C080007DCC89 /* Mesh.cpp */; };
12 12
 		8406D1D821E715E400E0EA0F /* libDK.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8406D1BF21E701FF00E0EA0F /* libDK.a */; };
13 13
 		8406D1F921E71C5500E0EA0F /* libDK.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8406D1C121E701FF00E0EA0F /* libDK.a */; };
14 14
 		841948EB1DDCBE6000E039F0 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 841948E91DDCBE5000E039F0 /* AppDelegate.m */; };
@@ -18,8 +18,10 @@
18 18
 		844A9A851DD0C080007DCC89 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 844A9A781DD0C080007DCC89 /* Assets.xcassets */; };
19 19
 		844A9A8B1DD0C08F007DCC89 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 844A9A741DD0C080007DCC89 /* Assets.xcassets */; };
20 20
 		844A9A8D1DD0C08F007DCC89 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 844A9A761DD0C080007DCC89 /* LaunchScreen.storyboard */; };
21
-		84B5FE4E20726C3600B52742 /* dkgl_new.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84B5FE4B20726C3600B52742 /* dkgl_new.cpp */; };
22
-		84B5FE4F20726C3600B52742 /* dkgl_new.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84B5FE4B20726C3600B52742 /* dkgl_new.cpp */; };
21
+		84A81E9D226443700060BCBB /* tiny_obj_loader.cc in Sources */ = {isa = PBXBuildFile; fileRef = 84A81E9C226443700060BCBB /* tiny_obj_loader.cc */; };
22
+		84A81E9E226443700060BCBB /* tiny_obj_loader.cc in Sources */ = {isa = PBXBuildFile; fileRef = 84A81E9C226443700060BCBB /* tiny_obj_loader.cc */; };
23
+		84A81EAF22644A7D0060BCBB /* dkgl_new.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84B5FE4B20726C3600B52742 /* dkgl_new.cpp */; };
24
+		84A81EB222644A7E0060BCBB /* dkgl_new.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84B5FE4B20726C3600B52742 /* dkgl_new.cpp */; };
23 25
 /* End PBXBuildFile section */
24 26
 
25 27
 /* Begin PBXContainerItemProxy section */
@@ -74,8 +76,8 @@
74 76
 		841948EC1DDCBE7500E039F0 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
75 77
 		841948ED1DDCBE7500E039F0 /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
76 78
 		8420EE1F1EE5BA6500A20933 /* Data */ = {isa = PBXFileReference; lastKnownFileType = folder; name = Data; path = ../Data; sourceTree = "<group>"; };
77
-		844A9A441DD0BCFD007DCC89 /* Texture_macOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Texture_macOS.app; sourceTree = BUILT_PRODUCTS_DIR; };
78
-		844A9A5C1DD0BEDD007DCC89 /* Texture_iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Texture_iOS.app; sourceTree = BUILT_PRODUCTS_DIR; };
79
+		844A9A441DD0BCFD007DCC89 /* Mesh_macOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Mesh_macOS.app; sourceTree = BUILT_PRODUCTS_DIR; };
80
+		844A9A5C1DD0BEDD007DCC89 /* Mesh_iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Mesh_iOS.app; sourceTree = BUILT_PRODUCTS_DIR; };
79 81
 		844A9A741DD0C080007DCC89 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
80 82
 		844A9A751DD0C080007DCC89 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
81 83
 		844A9A761DD0C080007DCC89 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = "<group>"; };
@@ -86,7 +88,8 @@
86 88
 		844A9A7D1DD0C080007DCC89 /* targetver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = targetver.h; sourceTree = "<group>"; };
87 89
 		844A9A7E1DD0C080007DCC89 /* SampleApp.ico */ = {isa = PBXFileReference; lastKnownFileType = image.ico; path = SampleApp.ico; sourceTree = "<group>"; };
88 90
 		844A9A7F1DD0C080007DCC89 /* SampleApp.rc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = SampleApp.rc; sourceTree = "<group>"; };
89
-		844A9A801DD0C080007DCC89 /* Texture.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Texture.cpp; sourceTree = "<group>"; };
91
+		844A9A801DD0C080007DCC89 /* Mesh.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Mesh.cpp; sourceTree = "<group>"; };
92
+		84A81E9C226443700060BCBB /* tiny_obj_loader.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = tiny_obj_loader.cc; path = ../Libs/tinyobjLoader/tiny_obj_loader.cc; sourceTree = "<group>"; };
90 93
 		84B5FE4B20726C3600B52742 /* dkgl_new.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = dkgl_new.cpp; sourceTree = "<group>"; };
91 94
 		84B81E9021E6FF8400E0C5FF /* app.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = app.h; sourceTree = "<group>"; };
92 95
 		84B81E9121E6FF8400E0C5FF /* util.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = util.h; sourceTree = "<group>"; };
@@ -145,8 +148,8 @@
145 148
 		844A9A451DD0BCFD007DCC89 /* Products */ = {
146 149
 			isa = PBXGroup;
147 150
 			children = (
148
-				844A9A441DD0BCFD007DCC89 /* Texture_macOS.app */,
149
-				844A9A5C1DD0BEDD007DCC89 /* Texture_iOS.app */,
151
+				844A9A441DD0BCFD007DCC89 /* Mesh_macOS.app */,
152
+				844A9A5C1DD0BEDD007DCC89 /* Mesh_iOS.app */,
150 153
 			);
151 154
 			name = Products;
152 155
 			sourceTree = "<group>";
@@ -154,7 +157,8 @@
154 157
 		844A9A461DD0BCFD007DCC89 /* Source Files */ = {
155 158
 			isa = PBXGroup;
156 159
 			children = (
157
-				844A9A801DD0C080007DCC89 /* Texture.cpp */,
160
+				84A81E9C226443700060BCBB /* tiny_obj_loader.cc */,
161
+				844A9A801DD0C080007DCC89 /* Mesh.cpp */,
158 162
 			);
159 163
 			name = "Source Files";
160 164
 			sourceTree = "<group>";
@@ -211,9 +215,9 @@
211 215
 /* End PBXGroup section */
212 216
 
213 217
 /* Begin PBXNativeTarget section */
214
-		844A9A431DD0BCFD007DCC89 /* Texture_macOS */ = {
218
+		844A9A431DD0BCFD007DCC89 /* Mesh_macOS */ = {
215 219
 			isa = PBXNativeTarget;
216
-			buildConfigurationList = 844A9A551DD0BCFD007DCC89 /* Build configuration list for PBXNativeTarget "Texture_macOS" */;
220
+			buildConfigurationList = 844A9A551DD0BCFD007DCC89 /* Build configuration list for PBXNativeTarget "Mesh_macOS" */;
217 221
 			buildPhases = (
218 222
 				844A9A401DD0BCFD007DCC89 /* Sources */,
219 223
 				844A9A411DD0BCFD007DCC89 /* Frameworks */,
@@ -224,14 +228,14 @@
224 228
 			dependencies = (
225 229
 				8406D1DC21E715FD00E0EA0F /* PBXTargetDependency */,
226 230
 			);
227
-			name = Texture_macOS;
231
+			name = Mesh_macOS;
228 232
 			productName = TestApp1;
229
-			productReference = 844A9A441DD0BCFD007DCC89 /* Texture_macOS.app */;
233
+			productReference = 844A9A441DD0BCFD007DCC89 /* Mesh_macOS.app */;
230 234
 			productType = "com.apple.product-type.application";
231 235
 		};
232
-		844A9A5B1DD0BEDD007DCC89 /* Texture_iOS */ = {
236
+		844A9A5B1DD0BEDD007DCC89 /* Mesh_iOS */ = {
233 237
 			isa = PBXNativeTarget;
234
-			buildConfigurationList = 844A9A701DD0BEDD007DCC89 /* Build configuration list for PBXNativeTarget "Texture_iOS" */;
238
+			buildConfigurationList = 844A9A701DD0BEDD007DCC89 /* Build configuration list for PBXNativeTarget "Mesh_iOS" */;
235 239
 			buildPhases = (
236 240
 				844A9A581DD0BEDD007DCC89 /* Sources */,
237 241
 				844A9A591DD0BEDD007DCC89 /* Frameworks */,
@@ -242,9 +246,9 @@
242 246
 			dependencies = (
243 247
 				8406D1DA21E715F400E0EA0F /* PBXTargetDependency */,
244 248
 			);
245
-			name = Texture_iOS;
249
+			name = Mesh_iOS;
246 250
 			productName = TestApp1_iOS;
247
-			productReference = 844A9A5C1DD0BEDD007DCC89 /* Texture_iOS.app */;
251
+			productReference = 844A9A5C1DD0BEDD007DCC89 /* Mesh_iOS.app */;
248 252
 			productType = "com.apple.product-type.application";
249 253
 		};
250 254
 /* End PBXNativeTarget section */
@@ -267,11 +271,12 @@
267 271
 					};
268 272
 				};
269 273
 			};
270
-			buildConfigurationList = 844A9A3F1DD0BCFD007DCC89 /* Build configuration list for PBXProject "Texture" */;
274
+			buildConfigurationList = 844A9A3F1DD0BCFD007DCC89 /* Build configuration list for PBXProject "Mesh" */;
271 275
 			compatibilityVersion = "Xcode 3.2";
272 276
 			developmentRegion = English;
273 277
 			hasScannedForEncodings = 0;
274 278
 			knownRegions = (
279
+				English,
275 280
 				en,
276 281
 				Base,
277 282
 			);
@@ -286,8 +291,8 @@
286 291
 			);
287 292
 			projectRoot = "";
288 293
 			targets = (
289
-				844A9A431DD0BCFD007DCC89 /* Texture_macOS */,
290
-				844A9A5B1DD0BEDD007DCC89 /* Texture_iOS */,
294
+				844A9A431DD0BCFD007DCC89 /* Mesh_macOS */,
295
+				844A9A5B1DD0BEDD007DCC89 /* Mesh_iOS */,
291 296
 			);
292 297
 		};
293 298
 /* End PBXProject section */
@@ -350,9 +355,10 @@
350 355
 			isa = PBXSourcesBuildPhase;
351 356
 			buildActionMask = 2147483647;
352 357
 			files = (
358
+				84A81EAF22644A7D0060BCBB /* dkgl_new.cpp in Sources */,
353 359
 				841948EF1DDCBE7B00E039F0 /* AppDelegate.m in Sources */,
354
-				84B5FE4E20726C3600B52742 /* dkgl_new.cpp in Sources */,
355
-				66DA89941DD3117F00338015 /* Texture.cpp in Sources */,
360
+				84A81E9D226443700060BCBB /* tiny_obj_loader.cc in Sources */,
361
+				66DA89941DD3117F00338015 /* Mesh.cpp in Sources */,
356 362
 			);
357 363
 			runOnlyForDeploymentPostprocessing = 0;
358 364
 		};
@@ -360,9 +366,10 @@
360 366
 			isa = PBXSourcesBuildPhase;
361 367
 			buildActionMask = 2147483647;
362 368
 			files = (
369
+				84A81EB222644A7E0060BCBB /* dkgl_new.cpp in Sources */,
363 370
 				841948EB1DDCBE6000E039F0 /* AppDelegate.m in Sources */,
364
-				84B5FE4F20726C3600B52742 /* dkgl_new.cpp in Sources */,
365
-				66DA89971DD3118000338015 /* Texture.cpp in Sources */,
371
+				84A81E9E226443700060BCBB /* tiny_obj_loader.cc in Sources */,
372
+				66DA89971DD3118000338015 /* Mesh.cpp in Sources */,
366 373
 			);
367 374
 			runOnlyForDeploymentPostprocessing = 0;
368 375
 		};
@@ -547,7 +554,7 @@
547 554
 /* End XCBuildConfiguration section */
548 555
 
549 556
 /* Begin XCConfigurationList section */
550
-		844A9A3F1DD0BCFD007DCC89 /* Build configuration list for PBXProject "Texture" */ = {
557
+		844A9A3F1DD0BCFD007DCC89 /* Build configuration list for PBXProject "Mesh" */ = {
551 558
 			isa = XCConfigurationList;
552 559
 			buildConfigurations = (
553 560
 				844A9A531DD0BCFD007DCC89 /* Debug */,
@@ -556,7 +563,7 @@
556 563
 			defaultConfigurationIsVisible = 0;
557 564
 			defaultConfigurationName = Release;
558 565
 		};
559
-		844A9A551DD0BCFD007DCC89 /* Build configuration list for PBXNativeTarget "Texture_macOS" */ = {
566
+		844A9A551DD0BCFD007DCC89 /* Build configuration list for PBXNativeTarget "Mesh_macOS" */ = {
560 567
 			isa = XCConfigurationList;
561 568
 			buildConfigurations = (
562 569
 				844A9A561DD0BCFD007DCC89 /* Debug */,
@@ -565,7 +572,7 @@
565 572
 			defaultConfigurationIsVisible = 0;
566 573
 			defaultConfigurationName = Release;
567 574
 		};
568
-		844A9A701DD0BEDD007DCC89 /* Build configuration list for PBXNativeTarget "Texture_iOS" */ = {
575
+		844A9A701DD0BEDD007DCC89 /* Build configuration list for PBXNativeTarget "Mesh_iOS" */ = {
569 576
 			isa = XCConfigurationList;
570 577
 			buildConfigurations = (
571 578
 				844A9A711DD0BEDD007DCC89 /* Debug */,