Exemplo n.º 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);
        }
        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;

            if (Instancings.Data[id.Index].Data == null)
            {
                Instancings.Data[id.Index].Data = new byte[byteSize];
            }
            else
            {
                MyArrayHelpers.Reserve(ref Instancings.Data[id.Index].Data, byteSize);
            }

            //var rawBuffer = new MyVertexFormatCubeInstance[m_capacity];

            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 = new HalfVector4(instanceData[i].m_translationAndRot);

                    var colorMaskHSV = instanceData[i].ColorMaskHSV;

                    //Vector3 color = MyRender11.ColorFromMask(new Vector3(colorMaskHSV.X, colorMaskHSV.Y, colorMaskHSV.Z));
                    ptr[i].colorMaskHSV = new HalfVector4(colorMaskHSV);
                }
            }

            Instancings.Data[id.Index].Capacity = capacity;
            UpdateVertexBuffer(id);
        }