static MyMergeInstancingConstants() { Default = new MyMergeInstancingConstants() { InstanceIndex = -1 }; }
protected unsafe void SetProxyConstants(ref MyRenderableProxy_2 proxy, MyMergeInstancingConstants?arg = null) { MyMergeInstancingConstants constants = arg ?? MyMergeInstancingConstants.Default; int version = constants.GetHashCode(); if (constants.GetHashCode() != proxy.ObjectConstants.Version) { int size = sizeof(MyMergeInstancingConstants); var buffer = new byte[sizeof(MyMergeInstancingConstants)]; proxy.ObjectConstants = new MyConstantsPack() { BindFlag = MyBindFlag.BIND_VS, CB = MyCommon.GetObjectCB(size), Version = version, Data = buffer }; fixed(byte *dstPtr = buffer) { #if XB1 SharpDX.Utilities.CopyMemory(new IntPtr(dstPtr), new IntPtr(&constants), size); #else // !XB1 MyMemory.CopyMemory(new IntPtr(dstPtr), new IntPtr(&constants), (uint)size); #endif // !XB1 } } MyRenderUtils.MoveConstants(RC, ref proxy.ObjectConstants); MyRenderUtils.SetConstants(RC, ref proxy.ObjectConstants, MyCommon.OBJECT_SLOT); ++Stats.ObjectConstantsChanges; }
private void DrawSubmesh(ref MyRenderableProxy_2 proxy, ref MyDrawSubmesh_2 submesh, int instanceIndex) { var material = MyMaterials1.ProxyPool.Data[submesh.MaterialId.Index]; RC.MoveConstants(ref material.MaterialConstants); RC.SetConstants(ref material.MaterialConstants, MyCommon.MATERIAL_SLOT); RC.SetSRVs(ref material.MaterialSRVs); MyMergeInstancingConstants constants = new MyMergeInstancingConstants(); constants.InstanceIndex = instanceIndex; constants.StartIndex = submesh.Start; SetProxyConstants(ref proxy, constants); if (proxy.InstanceCount == 0) { switch (submesh.DrawCommand) { case MyDrawCommandEnum.DrawIndexed: RC.DeviceContext.DrawIndexed(submesh.Count, submesh.Start, submesh.BaseVertex); break; case MyDrawCommandEnum.Draw: RC.DeviceContext.Draw(submesh.Count, submesh.Start); break; default: break; } } else { switch (submesh.DrawCommand) { case MyDrawCommandEnum.DrawIndexed: RC.DeviceContext.DrawIndexedInstanced(submesh.Count, proxy.InstanceCount, submesh.Start, submesh.BaseVertex, proxy.StartInstance); break; case MyDrawCommandEnum.Draw: RC.DeviceContext.DrawInstanced(submesh.Count, proxy.InstanceCount, submesh.Start, proxy.StartInstance); break; default: break; } } Stats.Submeshes++; }
protected unsafe void SetProxyConstants(ref MyRenderableProxy_2 proxy, MyMergeInstancingConstants? arg = null) { MyMergeInstancingConstants constants = arg ?? MyMergeInstancingConstants.Default; int version = constants.GetHashCode(); if (constants.GetHashCode() != proxy.ObjectConstants.Version) { int size = sizeof(MyMergeInstancingConstants); var buffer = new byte[sizeof(MyMergeInstancingConstants)]; proxy.ObjectConstants = new MyConstantsPack() { BindFlag = MyBindFlag.BIND_VS, CB = MyCommon.GetObjectCB(size), Version = version, Data = buffer }; fixed (byte* dstPtr = buffer) { MyMemory.CopyMemory(new IntPtr(dstPtr), new IntPtr(&constants), (uint)size); } } RC.MoveConstants(ref proxy.ObjectConstants); RC.SetConstants(ref proxy.ObjectConstants, MyCommon.OBJECT_SLOT); ++Stats.ObjectConstantsChanges; }
private void DrawSubmesh(ref MyRenderableProxy_2 proxy, ref MyDrawSubmesh_2 submesh, int instanceIndex) { var material = MyMaterials1.ProxyPool.Data[submesh.MaterialId.Index]; MyRenderUtils.MoveConstants(RC, ref material.MaterialConstants); MyRenderUtils.SetConstants(RC, ref material.MaterialConstants, MyCommon.MATERIAL_SLOT); MyRenderUtils.SetSrvs(RC, ref material.MaterialSrvs); MyMergeInstancingConstants constants = new MyMergeInstancingConstants(); constants.InstanceIndex = instanceIndex; constants.StartIndex = submesh.Start; SetProxyConstants(ref proxy, constants); if (proxy.InstanceCount == 0) { switch (submesh.DrawCommand) { case MyDrawCommandEnum.DrawIndexed: RC.DrawIndexed(submesh.Count, submesh.Start, submesh.BaseVertex); break; case MyDrawCommandEnum.Draw: RC.Draw(submesh.Count, submesh.Start); break; default: break; } } else { switch (submesh.DrawCommand) { case MyDrawCommandEnum.DrawIndexed: RC.DrawIndexedInstanced(submesh.Count, proxy.InstanceCount, submesh.Start, submesh.BaseVertex, proxy.StartInstance); break; case MyDrawCommandEnum.Draw: RC.DrawInstanced(submesh.Count, proxy.InstanceCount, submesh.Start, proxy.StartInstance); break; default: break; } } Stats.Submeshes++; }