Example #1
0
        internal static unsafe void UpdateCube(InstancingId id, List <MyCubeInstanceData> instanceData, int capacity)
        {
            Debug.Assert(id.Info.Type == MyRenderInstanceBufferType.Cube);

            var info = id.Info;

            var byteSize = info.Stride * capacity;

            MyArrayHelpers.InitOrReserve(ref Instancings.Data[id.Index].Data, byteSize);

            fixed(void *dst = Instancings.Data[id.Index].Data)
            {
                MyVertexFormatCubeInstance *ptr = (MyVertexFormatCubeInstance *)dst;

                for (int i = 0; i < instanceData.Count; i++)
                {
                    fixed(byte *pSource = instanceData[i].RawBones())
                    {
                        for (int j = 0; j < MyRender11Constants.CUBE_INSTANCE_BONES_NUM * 4; j++)
                        {
                            ptr[i].bones[j] = pSource[j];
                        }
                    }

                    ptr[i].translationRotation = instanceData[i].m_translationAndRot;

                    var colorMaskHSV = instanceData[i].ColorMaskHSV;

                    ptr[i].colorMaskHSV = colorMaskHSV;
                }
            }

            Instancings.Data[id.Index].VisibleCapacity = capacity;
            UpdateVertexBuffer(id);
        }
Example #2
0
        internal static unsafe void RebuildGeneric(InstancingId instancingId)
        {
            ProfilerShort.Begin("RebuildGeneric");
            Debug.Assert(instancingId.Info.Type == MyRenderInstanceBufferType.Generic);
            if (Instancings.Data[instancingId.Index].InstanceData == null)
            {
                ProfilerShort.End();
                Debug.Fail("Instance Data is null!");
                return;
            }

            var info = instancingId.Info;

            int capacity = Instancings.Data[instancingId.Index].InstanceData.Length;

            for (int maskIndex = 0; maskIndex < Instancings.Data[instancingId.Index].TotalCapacity; ++maskIndex)
            {
                if (!Instancings.Data[instancingId.Index].VisibilityMask[maskIndex])
                {
                    --capacity;
                }
            }

            var byteSize = info.Stride * capacity;

            MyArrayHelpers.InitOrReserve(ref Instancings.Data[instancingId.Index].Data, byteSize);

            fixed(void *src = Instancings.Data[instancingId.Index].InstanceData)
            {
                fixed(void *dst = Instancings.Data[instancingId.Index].Data)
                {
                    int currentIndex = 0;

                    for (int maskIndex = 0; maskIndex < Instancings.Data[instancingId.Index].TotalCapacity; ++maskIndex)
                    {
                        if (Instancings.Data[instancingId.Index].VisibilityMask[maskIndex])
                        {
                            SharpDX.Utilities.CopyMemory(new IntPtr(dst) + currentIndex * info.Stride, new IntPtr(src) + maskIndex * info.Stride, info.Stride);
                            ++currentIndex;
                        }
                    }
                }
            }

            Instancings.Data[instancingId.Index].VisibleCapacity = capacity;
            UpdateVertexBuffer(instancingId);
            ProfilerShort.End();
        }