//public void DrawUser<T>(int primitiveCount, T[] vertexes) //{ // GCHandle h = GCHandle.Alloc(vertexes, GCHandleType.Pinned); // try // { // unsafe // { // void* pter = Marshal.UnsafeAddrOfPinnedArrayElement(vertexes, 0).ToPointer(); // DrawUser(primitiveCount, pter, ClrRuntime.Runtime.SizeOf<T>()); // } // } // finally // { // h.Free(); // } //} //public void DrawIndexedUser<T, I>(int minVertexIndex, int numVertices, int primitiveCount, I[] indices, T[] vertices) //{ // GCHandle hv = GCHandle.Alloc(vertices, GCHandleType.Pinned); // GCHandle hi = GCHandle.Alloc(indices, GCHandleType.Pinned); // try // { // unsafe // { // void* pVertices = Marshal.UnsafeAddrOfPinnedArrayElement(vertices, 0).ToPointer(); // void* pIndices = Marshal.UnsafeAddrOfPinnedArrayElement(indices, 0).ToPointer(); // IndexFormat indexFormat = Marshal.SizeOf(typeof(I)) == 2 ? IndexFormat.Index16 : IndexFormat.Index32; // DrawIndexedUser(minVertexIndex, numVertices, primitiveCount, pIndices, indexFormat, pVertices, ClrRuntime.Runtime.SizeOf<T>()); // } // } // finally // { // hv.Free(); // hi.Free(); // } //} public InputLayout CreateInputLayout <T>(ShaderCode bytecode) where T : struct { var vd = VertexDescriptor.GetDescriptor <T>(); return(CreateInputLayout(vd.Elements, bytecode)); }
public IndexedBufferView(IntPtr vertexPter, VertexDescriptor vd, IASemantic semantic, int usageIndex, IntPtr indicesPter, int istride, int icount) { this.vertexPter = (byte *)vertexPter + vd.OffsetOf(semantic, usageIndex); this.vstride = vd.Size; this.indicesPter = (byte *)indicesPter; this.istride = istride; this.icount = icount; }
public static VertexDescriptor GetDescriptor <TVertex>() where TVertex : struct { VertexDescriptor vd = CACHE <TVertex> .vd; if (vd == null) { vd = new VertexDescriptor(typeof(TVertex)); CACHE <TVertex> .vd = vd; } CACHE <TVertex> .counter++; return(vd); }
public static VertexDescriptor GetDescriptor(Type type) { var ctype = typeof(CACHE <>); var genType = ctype.MakeGenericType(type); VertexDescriptor vd = (VertexDescriptor)genType.GetField("vd").GetValue(null); if (vd == null) { vd = new VertexDescriptor(type); genType.GetField("vd").SetValue(null, vd); } var counter = (int)genType.GetField("counter").GetValue(null); genType.GetField("counter").SetValue(null, counter + 1); return(vd); }
public static BufferView Texture0Reader(IntPtr baseAddr, VertexDescriptor vd) { return(new BufferView(baseAddr, vd, IASemantic.TextureCoordinate, 0)); }
public static BufferView TangentReader(IntPtr baseAddr, VertexDescriptor vd) { return(new BufferView(baseAddr, vd, IASemantic.Tangent, 0)); }
public static BufferView NormalReader(IntPtr baseAddr, VertexDescriptor vd) { return(new BufferView(baseAddr, vd, IASemantic.Normal, 0)); }
public static BufferView PositionReader(IntPtr baseAddr, VertexDescriptor vd) { return(new BufferView(baseAddr, vd, IASemantic.Position, 0)); }
public BufferView(IntPtr baseAddr, VertexDescriptor vd, IASemantic semantic, int usageIndex) { pter = baseAddr; offset = vd.OffsetOf(semantic, usageIndex); stride = vd.Size; }