Пример #1
0
        internal unsafe void UpdateCube(List <MyCubeInstanceData> instanceData, int capacity)
        {
            Debug.Assert(m_type == MyRenderInstanceBufferType.Cube);

            m_capacity = Math.Max(instanceData.Count, capacity);

            var rawBuffer = new MyVertexFormatCubeInstance[m_capacity];

            for (int instanceIndex = 0; instanceIndex < m_capacity; instanceIndex++)
            {
                fixed(byte *pSource = instanceData[instanceIndex].RawBones(), pTarget = rawBuffer[instanceIndex].bones)
                {
                    for (int boneIndex = 0; boneIndex < MyRender11Constants.CUBE_INSTANCE_BONES_NUM * 4; ++boneIndex)
                    {
                        pTarget[boneIndex] = pSource[boneIndex];
                    }
                }

                rawBuffer[instanceIndex].translationRotation = instanceData[instanceIndex].m_translationAndRot;
                rawBuffer[instanceIndex].colorMaskHSV        = instanceData[instanceIndex].ColorMaskHSV;
            }

            fixed(MyVertexFormatCubeInstance *dataPtr = rawBuffer)
            {
                MyHwBuffers.ResizeAndUpdateStaticVertexBuffer(ref VB, m_capacity, sizeof(MyVertexFormatCubeInstance), new IntPtr(dataPtr), m_debugName + " instances buffer");
            }

            BumpRenderable();
        }
        internal unsafe void UpdateCube(List <MyCubeInstanceData> instanceData, int capacity)
        {
            Debug.Assert(m_type == MyRenderInstanceBufferType.Cube);

            var instancesNum = instanceData.Count;

            if (m_capacity < instancesNum && VB != VertexBufferId.NULL)
            {
                MyHwBuffers.Destroy(VB);
                VB = VertexBufferId.NULL;
            }
            if (m_capacity < instancesNum)
            {
                m_capacity = Math.Max(instancesNum, capacity);
                VB         = MyHwBuffers.CreateVertexBuffer(m_capacity, sizeof(MyVertexFormatCubeInstance), null, m_debugName + " instances buffer");
            }

            var rawBuffer = new MyVertexFormatCubeInstance[m_capacity];

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

                rawBuffer[i].translationRotation = new HalfVector4(instanceData[i].m_translationAndRot);
                rawBuffer[i].colorMaskHSV        = new HalfVector4(instanceData[i].ColorMaskHSV);
            }

            fixed(MyVertexFormatCubeInstance *dataPtr = rawBuffer)
            {
                DataBox        srcBox    = new DataBox(new IntPtr(dataPtr));
                ResourceRegion dstRegion = new ResourceRegion(0, 0, 0, sizeof(MyVertexFormatCubeInstance) * instancesNum, 1, 1);

                MyRender11.ImmediateContext.UpdateSubresource(srcBox, VB.Buffer, 0, dstRegion);
            }

            BumpRenderable();
        }