示例#1
0
 public void CmdBindIndexBuffer(
     [FromProperty("this")] GenCommandBuffer commandBuffer,
     GenBuffer buffer,
     DeviceSize offset,
     VkIndexType indexType)
 {
 }
示例#2
0
 public void GetVertexCount(out ulong vertexCount, out ulong indexCount, out VkIndexType largestIndexType)
 {
     vertexCount      = 0;
     indexCount       = 0;
     largestIndexType = VkIndexType.Uint16;
     //compute size of stagging buf
     foreach (Schema.Mesh mesh in gltf.Meshes)
     {
         foreach (Schema.MeshPrimitive p in mesh.Primitives)
         {
             int accessorIdx;
             if (p.Attributes.TryGetValue("POSITION", out accessorIdx))
             {
                 vertexCount += (ulong)gltf.Accessors[accessorIdx].Count;
             }
             if (p.Indices != null)
             {
                 indexCount += (ulong)gltf.Accessors[(int)p.Indices].Count;
                 if (gltf.Accessors[(int)p.Indices].ComponentType == GltfComponentType.UnsignedInt)
                 {
                     largestIndexType = VkIndexType.Uint32;
                 }
             }
         }
     }
 }
示例#3
0
        public void SetIndices(IntPtr indices, IndexFormat format, int count, int elementOffset)
        {
            int elementSizeInBytes = FormatHelpers.GetIndexFormatElementByteSize(format);

            SetData(indices, elementSizeInBytes * count, elementOffset * elementSizeInBytes);
            IndexType = VkFormats.VeldridToVkIndexFormat(format);
        }
示例#4
0
 public void SetIndexBuffer(Buffer buffer, ulong offsets = 0, VkIndexType indexType = VkIndexType.Uint32)
 {
     if (buffer.handle != VkBuffer.Null)
     {
         vkCmdBindIndexBuffer(handle, buffer.handle, offsets, indexType);
     }
 }
示例#5
0
        /// <summary>
        /// Binds an index buffer to this command buffer
        /// </summary>
        /// <param name="buffer">buffer to bind</param>
        /// <param name="offset">offset into buffer</param>
        /// <returns>this</returns>
        public void BindIndexBuffer(IBindableBuffer buffer, VkIndexType type, ulong offset = 0)
        {
            var bh = buffer.BindingHandle.Handle;

            offset += buffer.Offset;
            VkCommandBuffer.vkCmdBindIndexBuffer(Handle, bh, offset, type);
        }
示例#6
0
 public unsafe void BindIndexBuffer(Buffer indexBuffer, VkIndexType indexType = VkIndexType.Uint16)
 {
     VulkanNative.vkCmdBindIndexBuffer(
         _handle,
         indexBuffer.Handle,
         0,
         indexType
         );
 }
示例#7
0
        public void CmdBindIndexBuffer(IVkBuffer buffer, ulong offset, VkIndexType indexType)
        {
            var _commandBuffer = Handle;
            var _buffer        = buffer?.Handle ?? VkBuffer.HandleType.Null;
            var _offset        = offset;
            var _indexType     = indexType;

            Direct.CmdBindIndexBuffer(_commandBuffer, _buffer, _offset, _indexType);
        }
示例#8
0
        public void CmdBindIndexBuffer(VkBuffer buffer, int offset, VkIndexType indexType)
        {
            if (m_State != CommandBufferState.Recording)
            {
                return;
            }

            m_Commands.Add(new Cmd_BindIndexBuffer((SoftwareBuffer)buffer, offset, indexType));
        }
示例#9
0
        public static void vkCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, int offset, VkIndexType indexType)
        {
            VkPreconditions.CheckNull(commandBuffer, nameof(commandBuffer));
            VkPreconditions.CheckNull(buffer, nameof(buffer));
            VkPreconditions.CheckRange(offset, 0, int.MaxValue, nameof(offset));

            GetCommandBuffer(commandBuffer).CmdBindIndexBuffer(buffer, offset, indexType);
        }
示例#10
0
 public static extern void CmdBindIndexBuffer(
     VkCommandBuffer commandBuffer,
     VkBuffer buffer,
     ulong offset,
     VkIndexType indexType
     );
示例#11
0
		//TODO: some buffer data are reused between primitives, and I duplicate the datas
		//buffers must be constructed without duplications
		public Mesh[] LoadMeshes<TVertex> (VkIndexType indexType, Buffer vbo, ulong vboOffset, Buffer ibo, ulong iboOffset) {
			ulong vCount, iCount;
			VkIndexType idxType;

			GetVertexCount (out vCount, out iCount, out idxType);

			int vertexByteSize = Marshal.SizeOf<TVertex> ();
			ulong vertSize = vCount * (ulong)vertexByteSize;
			ulong idxSize = iCount * (indexType == VkIndexType.Uint16 ? 2ul : 4ul);
			ulong size = vertSize + idxSize;

			int vertexCount = 0, indexCount = 0;
			int autoNamedMesh = 1;

			meshes = new List<Mesh> ();

			using (HostBuffer stagging = new HostBuffer (dev, VkBufferUsageFlags.TransferSrc, size)) {
				stagging.Map ();

				unsafe {

					Span<byte> stagVertPtrInit = new Span<byte>(stagging.MappedData.ToPointer (), (int)vertSize);
					Span<byte> stagIdxPtrInit = new Span<byte>((byte*)stagging.MappedData.ToPointer() + vertSize, (int)idxSize);
					Span<byte> stagVertPtr = stagVertPtrInit, stagIdxPtr = stagIdxPtrInit;

					foreach (GL.Mesh mesh in gltf.Meshes) {

						string meshName = mesh.Name;
						if (string.IsNullOrEmpty (meshName)) {
							meshName = "mesh_" + autoNamedMesh.ToString ();
							autoNamedMesh++;
						}
						Mesh m = new Mesh { Name = meshName };

						foreach (GL.MeshPrimitive p in mesh.Primitives) {
							GL.Accessor AccPos = null, AccNorm = null, AccUv = null, AccUv1 = null;

							int accessorIdx;
							if (p.Attributes.TryGetValue ("POSITION", out accessorIdx)) {
								AccPos = gltf.Accessors[accessorIdx];
								ensureBufferIsLoaded (gltf.BufferViews[(int)AccPos.BufferView].Buffer);
							}
							if (p.Attributes.TryGetValue ("NORMAL", out accessorIdx)) {
								AccNorm = gltf.Accessors[accessorIdx];
								ensureBufferIsLoaded (gltf.BufferViews[(int)AccNorm.BufferView].Buffer);
							}
							if (p.Attributes.TryGetValue ("TEXCOORD_0", out accessorIdx)) {
								AccUv = gltf.Accessors[accessorIdx];
								ensureBufferIsLoaded (gltf.BufferViews[(int)AccUv.BufferView].Buffer);
							}
							if (p.Attributes.TryGetValue ("TEXCOORD_1", out accessorIdx)) {
								AccUv1 = gltf.Accessors[accessorIdx];
								ensureBufferIsLoaded (gltf.BufferViews[(int)AccUv1.BufferView].Buffer);
							}

							Primitive prim = new Primitive {
								indexBase = (uint)indexCount,
								vertexBase = vertexCount,
								vertexCount = (uint)AccPos.Count,
								material = (uint)(p.Material ?? 0)
							};

							prim.bb.min.ImportFloatArray (AccPos.Min);
							prim.bb.max.ImportFloatArray (AccPos.Max);
							prim.bb.isValid = true;

							//Interleaving vertices
							Span<byte> inPosPtr = Span<byte>.Empty, inNormPtr = Span<byte>.Empty, inUvPtr = Span<byte>.Empty, inUv1Ptr = Span<byte>.Empty;

							GL.BufferView bv = gltf.BufferViews[(int)AccPos.BufferView];
							inPosPtr = loadedBuffers[bv.Buffer].Span.Slice (AccPos.ByteOffset + bv.ByteOffset);

							if (AccNorm != null) {
								bv = gltf.BufferViews[(int)AccNorm.BufferView];
								inNormPtr = loadedBuffers[bv.Buffer].Span.Slice (AccNorm.ByteOffset + bv.ByteOffset);
							}
							if (AccUv != null) {
								bv = gltf.BufferViews[(int)AccUv.BufferView];
								inUvPtr = loadedBuffers[bv.Buffer].Span.Slice (AccUv.ByteOffset + bv.ByteOffset);
							}
							if (AccUv1 != null) {
								bv = gltf.BufferViews[(int)AccUv1.BufferView];
								inUv1Ptr = loadedBuffers[bv.Buffer].Span.Slice (AccUv1.ByteOffset + bv.ByteOffset);
							}

							//TODO: use vertex attributes scan for copying data if they exists
							for (int j = 0; j < prim.vertexCount; j++) {
								inPosPtr.Slice (0, 12).CopyTo (stagVertPtr);
								inPosPtr = inPosPtr.Slice(12);
								if (!inNormPtr.IsEmpty) {
									inNormPtr.Slice (0, 12).CopyTo (stagVertPtr.Slice (12));
									inNormPtr = inNormPtr.Slice (12);
								}
								if (inUvPtr != null) {
									inUvPtr.Slice (0, 8).CopyTo (stagVertPtr.Slice (24));
									inUvPtr = inUvPtr.Slice (8);
								}
								if (inUv1Ptr != null) {
									inUv1Ptr.Slice (0, 8).CopyTo (stagVertPtr.Slice (32));
									inUv1Ptr = inUvPtr.Slice (8);
								}
								stagVertPtr = stagVertPtr.Slice (vertexByteSize);
							}

							/*Span<byte> s = stagVertPtrInit;
							for (int i = 0; i < s.Length; i++)
								Console.Write (s[i].ToString ("X2") + (i % 32 == 0 ? "\n" : " "));*/


							//indices loading
							if (p.Indices != null) {
								GL.Accessor acc = gltf.Accessors[(int)p.Indices];
								bv = gltf.BufferViews[(int)acc.BufferView];

								Span<byte> inIdxPtr = loadedBuffers[bv.Buffer].Span.Slice (acc.ByteOffset + bv.ByteOffset);

								//TODO:double check this, I dont seems to increment stag pointer
								if (acc.ComponentType == GL.Accessor.ComponentTypeEnum.UNSIGNED_SHORT) {
									if (indexType == VkIndexType.Uint16) {
										inIdxPtr.Slice (0, acc.Count * 2).CopyTo (stagIdxPtr);
										stagIdxPtr = stagIdxPtr.Slice (acc.Count * 2);
									} else {

										Span<uint> usPtr = MemoryMarshal.Cast<byte, uint> (stagIdxPtr);
										Span<ushort> inPtr = MemoryMarshal.Cast < byte, ushort> (inIdxPtr);
										for (int i = 0; i < acc.Count; i++)
											usPtr[i] = inPtr[i];
										stagIdxPtr = stagIdxPtr.Slice (acc.Count * 4);
									}
								} else if (acc.ComponentType == GL.Accessor.ComponentTypeEnum.UNSIGNED_INT) {
									if (indexType == VkIndexType.Uint32) {
										inIdxPtr.Slice (0, acc.Count * 4).CopyTo (stagIdxPtr);
										stagIdxPtr = stagIdxPtr.Slice (acc.Count * 4);
									} else {
										Span<ushort> usPtr = MemoryMarshal.Cast<byte, ushort> (stagIdxPtr);
										Span<uint> inPtr = MemoryMarshal.Cast<byte, uint> (inIdxPtr);

										for (int i = 0; i < acc.Count; i++) 
											usPtr[i] = (ushort)inPtr[i];
										stagIdxPtr = stagIdxPtr.Slice (acc.Count * 2);
									}
								} else if (acc.ComponentType == GL.Accessor.ComponentTypeEnum.UNSIGNED_BYTE) {
									//convert
									if (indexType == VkIndexType.Uint16) {
										Span<ushort> usPtr = MemoryMarshal.Cast<byte, ushort> (stagIdxPtr);
										for (int i = 0; i < acc.Count; i++)
											usPtr[i] = (ushort)inIdxPtr[i];
										stagIdxPtr = stagIdxPtr.Slice (acc.Count * 2);
									} else {
										Span<uint> usPtr = MemoryMarshal.Cast<byte, uint> (stagIdxPtr);
										for (int i = 0; i < acc.Count; i++)
											usPtr[i] = (uint)inIdxPtr[i];
										stagIdxPtr = stagIdxPtr.Slice (acc.Count * 4);
									}
								} else
									throw new NotImplementedException ();

								prim.indexCount = (uint)acc.Count;
								indexCount += acc.Count;
							}

							m.AddPrimitive (prim);

							vertexCount += AccPos.Count;
						}
						meshes.Add (m);
					}

					/*ReadOnlySpan<byte> tmp = new ReadOnlySpan<byte> (stagging.MappedData.ToPointer (), (int)size);
					Memory<byte> mtmp = new Memory<byte> (tmp.ToArray());
					mtmp.Dump();*/
				}

				stagging.Unmap ();

				PrimaryCommandBuffer cmd = cmdPool.AllocateCommandBuffer ();
				cmd.Start (VkCommandBufferUsageFlags.OneTimeSubmit);

				stagging.CopyTo (cmd, vbo, vertSize, 0, vboOffset);
				if (iCount>0)
					stagging.CopyTo (cmd, ibo, idxSize, vertSize, iboOffset);

				cmd.End ();

				transferQ.Submit (cmd);

				dev.WaitIdle ();
				cmd.Free ();

			}

			return meshes.ToArray ();
		}
示例#12
0
 public Cmd_BindIndexBuffer(SoftwareBuffer buffer, int offset, VkIndexType indexType)
 {
     this.buffer    = buffer;
     this.offset    = offset;
     this.indexType = indexType;
 }
示例#13
0
 public void SetIndices(IntPtr indices, IndexFormat format, int count)
 {
     SetData(indices, FormatHelpers.GetIndexFormatElementByteSize(format) * count);
     IndexType = VkFormats.VeldridToVkIndexFormat(format);
 }
示例#14
0
 public void SetIndices(ushort[] indices, int stride, int elementOffset)
 {
     SetData(indices, elementOffset * sizeof(ushort));
     IndexType = VkIndexType.Uint16;
 }
示例#15
0
 public void SetIndices(ushort[] indices)
 {
     SetData(indices);
     IndexType = VkIndexType.Uint16;
 }
示例#16
0
 public void SetIndices(uint[] indices)
 {
     SetData(indices);
     IndexType = VkIndexType.Uint32;
 }
示例#17
0
 public void BindIndexBuffer(Buffer buffer, ulong offset, VkIndexType indexType)
 {
     Device.Commands.cmdBindIndexBuffer(commandBuffer, buffer.Native, offset, indexType);
 }
示例#18
0
        public unsafe List <Mesh> LoadMeshes()
        {
            GetVertexCount(out var vCount, out var iCount, out var idxType);

            IndexType = idxType;

            int vertexByteSize = Marshal.SizeOf <TVertex>();

            ulong vertSize  = (ulong)((int)vCount * vertexByteSize);
            ulong indexSize = (ulong)iCount * (idxType is VkIndexType.Uint16 ? 2ul : 4ul);

            int autoNamedMesh = 1;

            int vertexCount = 0, indexCount = 0;

            VertexBuffer = new(_device, new()
            {
                BufferFlags = BufferFlags.VertexBuffer,
                Usage = ResourceUsage.CPU_To_GPU,
                SizeInBytes = (int)vertSize
            });

            IndexBuffer = new(_device, new()
            {
                BufferFlags = BufferFlags.IndexBuffer,
                Usage = ResourceUsage.CPU_To_GPU,
                SizeInBytes = (int)indexSize,
            });



            Meshes = new();


            IEnumerable <PropertyInfo> propertyInfos = typeof(TVertex).GetTypeInfo().GetRuntimeProperties();


            byte *stagVertPtrInit = (byte *)VertexBuffer.Map();
            byte *stagIdxPtrInit  = (byte *)(IndexBuffer.Map());
            byte *stagVertPtr     = stagVertPtrInit;
            byte *stagIdxPtr      = stagIdxPtrInit;

            foreach (Schema.Mesh mesh in gltf.Meshes)
            {
                string meshName = mesh.Name;
                if (string.IsNullOrEmpty(meshName))
                {
                    meshName = "mesh_" + autoNamedMesh.ToString();
                    autoNamedMesh++;
                }
                Mesh m = new Mesh {
                    Name = meshName
                };

                foreach (Schema.MeshPrimitive p in mesh.Primitives)
                {
                    Schema.Accessor AccPos = null, AccNorm = null, AccUv = null, AccUv1 = null, AccColor = null, AccTan = null, Accjoint = null, Accweights = null;

                    if (p.Attributes.TryGetValue("POSITION", out int accessorIdx))
                    {
                        AccPos = gltf.Accessors[accessorIdx];
                        EnsureBufferIsLoaded(gltf.BufferViews[(int)AccPos.BufferView].Buffer);
                    }
                    if (p.Attributes.TryGetValue("NORMAL", out accessorIdx))
                    {
                        AccNorm = gltf.Accessors[accessorIdx];
                        EnsureBufferIsLoaded(gltf.BufferViews[(int)AccNorm.BufferView].Buffer);
                    }
                    if (p.Attributes.TryGetValue("TEXCOORD_0", out accessorIdx))
                    {
                        AccUv = gltf.Accessors[accessorIdx];
                        EnsureBufferIsLoaded(gltf.BufferViews[(int)AccUv.BufferView].Buffer);
                    }
                    if (p.Attributes.TryGetValue("TEXCOORD_1", out accessorIdx))
                    {
                        AccUv1 = gltf.Accessors[accessorIdx];
                        EnsureBufferIsLoaded(gltf.BufferViews[(int)AccUv1.BufferView].Buffer);
                    }

                    if (p.Attributes.TryGetValue("COLOR_0", out accessorIdx))
                    {
                        AccColor = gltf.Accessors[accessorIdx];
                        EnsureBufferIsLoaded(gltf.BufferViews[(int)AccColor.BufferView].Buffer);
                        ColorType = AccColor.Type is GltfType.Vec3 ? ColorType.Vec3 : ColorType.Vec4;
                    }

                    if (p.Attributes.TryGetValue("TANGENT", out accessorIdx))
                    {
                        AccTan = gltf.Accessors[accessorIdx];
                        EnsureBufferIsLoaded(gltf.BufferViews[(int)AccTan.BufferView].Buffer);
                    }

                    if (Options.Skinning)
                    {
                        if (p.Attributes.TryGetValue("JOINTS_0", out accessorIdx))
                        {
                            Accjoint = gltf.Accessors[accessorIdx];
                            EnsureBufferIsLoaded(gltf.BufferViews[(int)Accjoint.BufferView].Buffer);
                        }

                        if (p.Attributes.TryGetValue("WEIGHTS_0", out accessorIdx))
                        {
                            Accweights = gltf.Accessors[accessorIdx];
                            EnsureBufferIsLoaded(gltf.BufferViews[(int)Accweights.BufferView].Buffer);
                        }
                    }



                    Primitive prim = new()
                    {
                        FirstIndex  = indexCount,
                        FirstVertex = vertexCount,
                        VertexCount = AccPos.Count,
                        Material    = p.Material ?? 0
                    };

                    //prim.BoundingBox.Min.ImportFloatArray(AccPos.Min);
                    //prim.BoundingBox.Max.ImportFloatArray(AccPos.Max);
                    //prim.BoundingBox.IsValid = true;

                    //Interleaving vertices
                    byte *inPosPtr     = null;
                    byte *inNormPtr    = null;
                    byte *inUvPtr      = null;
                    byte *inUv1Ptr     = null;
                    byte *inColorPtr   = null;
                    byte *inTanPtr     = null;
                    byte *inJointPtr   = null;
                    byte *inWeightsPtr = null;


                    Schema.BufferView bv = gltf.BufferViews[(int)AccPos.BufferView !];
                    inPosPtr  = (byte *)bufferHandles[bv.Buffer].AddrOfPinnedObject().ToPointer();
                    inPosPtr += AccPos.ByteOffset + bv.ByteOffset;

                    if (AccNorm is not null)
                    {
                        bv         = gltf.BufferViews[(int)AccNorm.BufferView !];
示例#19
0
        //TODO: some buffer data are reused between primitives, and I duplicate the datas
        //buffers must be constructed without duplications
        public Mesh[] LoadMeshes <TVertex> (VkIndexType indexType, Buffer vbo, ulong vboOffset, Buffer ibo, ulong iboOffset)
        {
            ulong       vCount, iCount;
            VkIndexType idxType;

            GetVertexCount(out vCount, out iCount, out idxType);

            int   vertexByteSize = Marshal.SizeOf <TVertex> ();
            ulong vertSize       = vCount * (ulong)vertexByteSize;
            ulong idxSize        = iCount * (indexType == VkIndexType.Uint16 ? 2ul : 4ul);
            ulong size           = vertSize + idxSize;

            int vertexCount = 0, indexCount = 0;
            int autoNamedMesh = 1;

            meshes = new List <Mesh> ();

            using (HostBuffer stagging = new HostBuffer(dev, VkBufferUsageFlags.TransferSrc, size)) {
                stagging.Map();

                unsafe {
                    byte *stagVertPtrInit = (byte *)stagging.MappedData.ToPointer();
                    byte *stagIdxPtrInit  = (byte *)(stagging.MappedData.ToPointer()) + vertSize;
                    byte *stagVertPtr     = stagVertPtrInit;
                    byte *stagIdxPtr      = stagIdxPtrInit;

                    foreach (GL.Mesh mesh in gltf.Meshes)
                    {
                        string meshName = mesh.Name;
                        if (string.IsNullOrEmpty(meshName))
                        {
                            meshName = "mesh_" + autoNamedMesh.ToString();
                            autoNamedMesh++;
                        }
                        Mesh m = new Mesh {
                            Name = meshName
                        };

                        foreach (GL.MeshPrimitive p in mesh.Primitives)
                        {
                            GL.Accessor AccPos = null, AccNorm = null, AccUv = null, AccUv1 = null;

                            int accessorIdx;
                            if (p.Attributes.TryGetValue("POSITION", out accessorIdx))
                            {
                                AccPos = gltf.Accessors[accessorIdx];
                                EnsureBufferIsLoaded(gltf.BufferViews[(int)AccPos.BufferView].Buffer);
                            }
                            if (p.Attributes.TryGetValue("NORMAL", out accessorIdx))
                            {
                                AccNorm = gltf.Accessors[accessorIdx];
                                EnsureBufferIsLoaded(gltf.BufferViews[(int)AccNorm.BufferView].Buffer);
                            }
                            if (p.Attributes.TryGetValue("TEXCOORD_0", out accessorIdx))
                            {
                                AccUv = gltf.Accessors[accessorIdx];
                                EnsureBufferIsLoaded(gltf.BufferViews[(int)AccUv.BufferView].Buffer);
                            }
                            if (p.Attributes.TryGetValue("TEXCOORD_1", out accessorIdx))
                            {
                                AccUv1 = gltf.Accessors[accessorIdx];
                                EnsureBufferIsLoaded(gltf.BufferViews[(int)AccUv1.BufferView].Buffer);
                            }

                            Primitive prim = new Primitive {
                                indexBase   = (uint)indexCount,
                                vertexBase  = vertexCount,
                                vertexCount = (uint)AccPos.Count,
                                material    = (uint)(p.Material ?? 0)
                            };

                            prim.bb.min.ImportFloatArray(AccPos.Min);
                            prim.bb.max.ImportFloatArray(AccPos.Max);
                            prim.bb.isValid = true;

                            //Interleaving vertices
                            byte *inPosPtr = null, inNormPtr = null, inUvPtr = null, inUv1Ptr = null;

                            GL.BufferView bv = gltf.BufferViews[(int)AccPos.BufferView];
                            inPosPtr  = (byte *)bufferHandles[bv.Buffer].AddrOfPinnedObject().ToPointer();
                            inPosPtr += AccPos.ByteOffset + bv.ByteOffset;

                            if (AccNorm != null)
                            {
                                bv         = gltf.BufferViews[(int)AccNorm.BufferView];
                                inNormPtr  = (byte *)bufferHandles[bv.Buffer].AddrOfPinnedObject().ToPointer();
                                inNormPtr += AccNorm.ByteOffset + bv.ByteOffset;
                            }
                            if (AccUv != null)
                            {
                                bv       = gltf.BufferViews[(int)AccUv.BufferView];
                                inUvPtr  = (byte *)bufferHandles[bv.Buffer].AddrOfPinnedObject().ToPointer();
                                inUvPtr += AccUv.ByteOffset + bv.ByteOffset;
                            }
                            if (AccUv1 != null)
                            {
                                bv        = gltf.BufferViews[(int)AccUv1.BufferView];
                                inUv1Ptr  = (byte *)bufferHandles[bv.Buffer].AddrOfPinnedObject().ToPointer();
                                inUv1Ptr += AccUv1.ByteOffset + bv.ByteOffset;
                            }


                            for (int j = 0; j < prim.vertexCount; j++)
                            {
                                System.Buffer.MemoryCopy(inPosPtr, stagVertPtr, 12, 12);
                                inPosPtr += 12;
                                if (inNormPtr != null)
                                {
                                    System.Buffer.MemoryCopy(inNormPtr, stagVertPtr + 12, 12, 12);
                                    inNormPtr += 12;
                                }
                                if (inUvPtr != null)
                                {
                                    System.Buffer.MemoryCopy(inUvPtr, stagVertPtr + 24, 8, 8);
                                    inUvPtr += 8;
                                }
                                if (inUv1Ptr != null)
                                {
                                    System.Buffer.MemoryCopy(inUv1Ptr, stagVertPtr + 32, 8, 8);
                                    inUv1Ptr += 8;
                                }
                                stagVertPtr += vertexByteSize;
                            }

                            //indices loading
                            if (p.Indices != null)
                            {
                                GL.Accessor acc = gltf.Accessors[(int)p.Indices];
                                bv = gltf.BufferViews[(int)acc.BufferView];

                                byte *inIdxPtr = (byte *)bufferHandles[bv.Buffer].AddrOfPinnedObject().ToPointer();
                                inIdxPtr += acc.ByteOffset + bv.ByteOffset;

                                //TODO:double check this, I dont seems to increment stag pointer
                                if (acc.ComponentType == GL.Accessor.ComponentTypeEnum.UNSIGNED_SHORT)
                                {
                                    if (indexType == VkIndexType.Uint16)
                                    {
                                        System.Buffer.MemoryCopy(inIdxPtr, stagIdxPtr, (long)acc.Count * 2, (long)acc.Count * 2);
                                        stagIdxPtr += (long)acc.Count * 2;
                                    }
                                    else
                                    {
                                        uint *  usPtr = (uint *)stagIdxPtr;
                                        ushort *inPtr = (ushort *)inIdxPtr;
                                        for (int i = 0; i < acc.Count; i++)
                                        {
                                            usPtr[i] = inPtr[i];
                                        }
                                        stagIdxPtr += (long)acc.Count * 4;
                                    }
                                }
                                else if (acc.ComponentType == GL.Accessor.ComponentTypeEnum.UNSIGNED_INT)
                                {
                                    if (indexType == VkIndexType.Uint32)
                                    {
                                        System.Buffer.MemoryCopy(inIdxPtr, stagIdxPtr, (long)acc.Count * 4, (long)acc.Count * 4);
                                        stagIdxPtr += (long)acc.Count * 4;
                                    }
                                    else
                                    {
                                        ushort *usPtr = (ushort *)stagIdxPtr;
                                        uint *  inPtr = (uint *)inIdxPtr;
                                        for (int i = 0; i < acc.Count; i++)
                                        {
                                            usPtr[i] = (ushort)inPtr[i];
                                        }
                                        stagIdxPtr += (long)acc.Count * 2;
                                    }
                                }
                                else if (acc.ComponentType == GL.Accessor.ComponentTypeEnum.UNSIGNED_BYTE)
                                {
                                    //convert
                                    if (indexType == VkIndexType.Uint16)
                                    {
                                        ushort *usPtr = (ushort *)stagIdxPtr;
                                        for (int i = 0; i < acc.Count; i++)
                                        {
                                            usPtr[i] = (ushort)inIdxPtr[i];
                                        }
                                        stagIdxPtr += (long)acc.Count * 2;
                                    }
                                    else
                                    {
                                        uint *usPtr = (uint *)stagIdxPtr;
                                        for (int i = 0; i < acc.Count; i++)
                                        {
                                            usPtr[i] = (uint)inIdxPtr[i];
                                        }
                                        stagIdxPtr += (long)acc.Count * 4;
                                    }
                                }
                                else
                                {
                                    throw new NotImplementedException();
                                }

                                prim.indexCount = (uint)acc.Count;
                                indexCount     += acc.Count;
                            }

                            m.AddPrimitive(prim);

                            vertexCount += AccPos.Count;
                        }
                        meshes.Add(m);
                    }
                }

                stagging.Unmap();

                CommandBuffer cmd = cmdPool.AllocateCommandBuffer();
                cmd.Start(VkCommandBufferUsageFlags.OneTimeSubmit);

                stagging.CopyTo(cmd, vbo, vertSize, 0, vboOffset);
                if (iCount > 0)
                {
                    stagging.CopyTo(cmd, ibo, idxSize, vertSize, iboOffset);
                }

                cmd.End();

                transferQ.Submit(cmd);

                dev.WaitIdle();
                cmd.Free();
            }

            return(meshes.ToArray());
        }
示例#20
0
 internal extern static void vkCmdBindIndexBuffer(IntPtr commandBuffer, UInt64 buffer, UInt64 offset, VkIndexType indexType);
示例#21
0
 public void BindIndexBuffer(Buffer indices, VkIndexType indexType = VkIndexType.Uint32, ulong offset = 0)
 {
     vkCmdBindIndexBuffer(handle, indices.handle, offset, indexType);
 }
示例#22
0
 public void CmdBindIndexBuffer(
     [FromProperty("this")] GenCommandBuffer commandBuffer,
     GenBuffer buffer,
     DeviceSize offset,
     VkIndexType indexType)
 { }
示例#23
0
 internal void CmdBindIndexBuffer(VkBuffer buffer, int offset, VkIndexType indexType)
 {
 }
示例#24
0
 public void BindIndexBuffer(DeviceBuffer buffer, VkIndexType indexType, ulong offset = 0)
 {
     CheckBegun();
     CheckInRenderPass();
     vkCmdBindIndexBuffer(vkCmd, buffer.vkBuffer, offset, indexType);
 }
示例#25
0
 public void CmdBindIndexBuffer(IVkBuffer buffer, ulong offset, VkIndexType indexType)
 {
     var _commandBuffer = Handle;
     var _buffer = buffer?.Handle ?? VkBuffer.HandleType.Null;
     var _offset = offset;
     var _indexType = indexType;
     Direct.CmdBindIndexBuffer(_commandBuffer, _buffer, _offset, _indexType);
 }