void LoadAssets() { // Generate meshes MDLMesh mdl = MDLMesh.CreateBox(new Vector3(2f, 2f, 2f), new Vector3i(1, 1, 1), MDLGeometryType.Triangles, false, new MTKMeshBufferAllocator(device)); NSError error; boxMesh = new MTKMesh(mdl, device, out error); // Allocate one region of memory for the uniform buffer dynamicConstantBuffer = device.CreateBuffer(MaxBytesPerFrame, (MTLResourceOptions)0); dynamicConstantBuffer.Label = "UniformBuffer"; // Load the fragment program into the library IMTLFunction fragmentProgram = defaultLibrary.CreateFunction("lighting_fragment"); // Load the vertex program into the library IMTLFunction vertexProgram = defaultLibrary.CreateFunction("lighting_vertex"); // Create a vertex descriptor from the MTKMesh MTLVertexDescriptor vertexDescriptor = MTLVertexDescriptor.FromModelIO(boxMesh.VertexDescriptor); vertexDescriptor.Layouts[0].StepRate = 1; vertexDescriptor.Layouts[0].StepFunction = MTLVertexStepFunction.PerVertex; // Create a reusable pipeline state var pipelineStateDescriptor = new MTLRenderPipelineDescriptor { Label = "MyPipeline", SampleCount = view.SampleCount, VertexFunction = vertexProgram, FragmentFunction = fragmentProgram, VertexDescriptor = vertexDescriptor, DepthAttachmentPixelFormat = view.DepthStencilPixelFormat, StencilAttachmentPixelFormat = view.DepthStencilPixelFormat }; pipelineStateDescriptor.ColorAttachments[0].PixelFormat = view.ColorPixelFormat; pipelineState = device.CreateRenderPipelineState(pipelineStateDescriptor, out error); if (pipelineState == null) { Console.WriteLine("Failed to created pipeline state, error {0}", error); } var depthStateDesc = new MTLDepthStencilDescriptor { DepthCompareFunction = MTLCompareFunction.Less, DepthWriteEnabled = true }; depthState = device.CreateDepthStencilState(depthStateDesc); }
public void Setup() { TestRuntime.AssertXcodeVersion(7, 0); #if !MONOMAC if (Runtime.Arch == Arch.SIMULATOR && IntPtr.Size == 4) { // There's a bug in the i386 version of objc_msgSend where it doesn't preserve SIMD arguments // when resizing the cache of method selectors for a type. So here we call all selectors we can // find, so that the subsequent tests don't end up producing any cache resize (radar #21630410). object dummy; using (var obj = MDLMesh.CreateBox(Vector3.Zero, Vector3i.Zero, MDLGeometryType.Triangles, true, null)) { obj.AddAttribute("foo", MDLVertexFormat.Char); // obj.AddNormals (null, 0); // throws NSInvalidArgumentException, need to figure out valid arguments // obj.AddTangentBasis ("foo", "bar", "zap"); // throws "Need float or half UV components Need float or half UV components" // obj.AddTangentBasisWithNormals ("foo", "bar", "zap"); // throws "Need float or half UV components Reason: Need float or half UV components" dummy = obj.BoundingBox; // obj.GenerateAmbientOcclusionTexture (1, 1, new MDLObject [] { }, "name", "name"); // obj.GenerateAmbientOcclusionVertexColors (1, 1, new MDLObject[] {}, "name"); // obj.GenerateAmbientOcclusionVertexColors (1.1, 1, new MDLObject[] [] { }, "name"); // obj.GenerateLightMapTexture (Vector2i.Zero, new MDLLight[] {}, new MDLObject[] {}, "str", "str"); // obj.GenerateLightMapVertexColors (new MDLLight[] { }, new MDLObject[] { }, "v"); obj.MakeVerticesUnique(); dummy = obj.Submeshes; dummy = obj.VertexBuffers; dummy = obj.VertexCount; dummy = obj.VertexDescriptor; } using (var obj = MDLMesh.CreateCylindroid(1, Vector2.Zero, 3, 0, MDLGeometryType.Triangles, false, null)) { } using (var obj = MDLMesh.CreateEllipsoid(Vector3.Zero, 3, 2, MDLGeometryType.Triangles, false, false, null)) { } using (var obj = MDLMesh.CreateEllipticalCone(0, Vector2.Zero, 3, 1, MDLGeometryType.Triangles, false, null)) { } using (var obj = MDLMesh.CreateIcosahedron(0, false, null)) { } using (var obj = MDLMesh.CreatePlane(new Vector2(1, 1), new Vector2i(1, 1), MDLGeometryType.Triangles, null)) { } using (var obj = MDLMesh.CreateSphere(new Vector3(1, 2, 3), new Vector2i(4, 5), MDLGeometryType.Triangles, true, null)) { } using (var obj = MDLMesh.CreateHemisphere(new Vector3(1, 2, 3), new Vector2i(4, 5), MDLGeometryType.Triangles, true, true, null)) { } using (var obj = MDLMesh.CreateCapsule(new Vector3(1, 2, 3), new Vector2i(4, 5), MDLGeometryType.Triangles, true, 10, null)) { } using (var obj = MDLMesh.CreateCone(new Vector3(1, 2, 3), new Vector2i(4, 5), MDLGeometryType.Triangles, true, true, null)) { } // using (var obj = MDLMesh.CreateSubdividedMesh (new MDLMesh (), 0, 0)) { // } } #endif }
public void CreateBoxWithDimensonTest() { Vector3 V3 = new Vector3(1, 2, 3); Vector3i V3i = new Vector3i(4, 5, 6); using (var obj = MDLMesh.CreateBox(V3, V3i, MDLGeometryType.Triangles, true, null)) { Assert.IsNotNull(obj, "obj"); Asserts.AreEqual(new MDLAxisAlignedBoundingBox { MaxBounds = new Vector3(0.5f, 1, 1.5f), MinBounds = new Vector3(-0.5f, -1, -1.5f) }, obj.BoundingBox, "BoundingBox"); Assert.AreEqual(1, obj.Submeshes.Count, "Submeshes Count"); Assert.AreEqual(1, obj.VertexBuffers.Length, "VertexBuffers Count"); Assert.AreEqual(TestRuntime.CheckXcodeVersion(7, 3) ? 214 : 24, obj.VertexCount, "VertexCount"); Assert.AreEqual(31, obj.VertexDescriptor.Attributes.Count, "VertexDescriptor Attributes Count"); Assert.AreEqual(31, obj.VertexDescriptor.Layouts.Count, "VertexDescriptor Layouts Count"); } }
public void CreateBoxTest() { Vector3 V3 = new Vector3(1, 2, 3); Vector3i V3i = new Vector3i(4, 5, 6); using (var obj = MDLMesh.CreateBox(V3, V3i, MDLGeometryType.Triangles, true, null)) { Assert.IsNotNull(obj, "obj"); Asserts.AreEqual(new MDLAxisAlignedBoundingBox { MaxBounds = new Vector3(0.5f, 1, 1.5f), MinBounds = new Vector3(-0.5f, -1, -1.5f) }, obj.BoundingBox, "BoundingBox"); Assert.AreEqual(1, obj.Submeshes.Count, "Submeshes Count"); Assert.AreEqual(1, obj.VertexBuffers.Length, "VertexBuffers Count"); // iOS 9.3 is the basis of tvOS 9.2 (hopefully they'll get in sync with iOS 10+) #if __TVOS__ bool nine3 = UIDevice.CurrentDevice.CheckSystemVersion(9, 2); #else bool nine3 = UIDevice.CurrentDevice.CheckSystemVersion(9, 3); #endif Assert.AreEqual(nine3 ? 214 : 24, obj.VertexCount, "VertexCount"); Assert.AreEqual(31, obj.VertexDescriptor.Attributes.Count, "VertexDescriptor Attributes Count"); Assert.AreEqual(31, obj.VertexDescriptor.Layouts.Count, "VertexDescriptor Layouts Count"); } }