internal unsafe void UpdateGeneric(List <MyInstanceData> instanceData, int capacity)
        {
            Debug.Assert(m_type == MyRenderInstanceBufferType.Generic);

            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(MyVertexFormatGenericInstance), null, m_debugName + " instances buffer");
            }

            fixed(MyInstanceData *dataPtr = instanceData.ToArray())
            {
                DataBox        srcBox    = new DataBox(new IntPtr(dataPtr));
                ResourceRegion dstRegion = new ResourceRegion(0, 0, 0, sizeof(MyVertexFormatGenericInstance) * instancesNum, 1, 1);

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

            BumpRenderable();
        }
示例#2
0
        private static void DoneDevice()
        {
            MyHwBuffers.Destroy(ref m_ib);
            MyHwBuffers.Destroy(ref m_activeListConstantBuffer);

            if (m_indirectDrawArgsBuffer != null)
            {
                m_indirectDrawArgsBuffer.Release(); m_indirectDrawArgsBuffer = null;
            }

#if DEBUG
            if (m_debugCounterBuffer != null)
            {
                m_debugCounterBuffer.Release(); m_debugCounterBuffer = null;
            }
#endif
            if (m_aliveIndexBuffer != null)
            {
                m_aliveIndexBuffer.Release(); m_aliveIndexBuffer = null;
            }
            if (m_deadListBuffer != null)
            {
                m_deadListBuffer.Release(); m_deadListBuffer = null;
            }
            if (m_particleBuffer != null)
            {
                m_particleBuffer.Release(); m_particleBuffer = null;
            }
            MyHwBuffers.Destroy(ref m_emitterConstantBuffer);
            MyHwBuffers.Destroy(ref m_emitterStructuredBuffer);
        }
示例#3
0
 private void DestroyIndexBuffer()
 {
     if (m_cubeIB != IndexBufferId.NULL)
     {
         MyHwBuffers.Destroy(m_cubeIB);
         m_cubeIB = IndexBufferId.NULL;
     }
 }
示例#4
0
 private void DestroyVertexBuffer()
 {
     if (m_cascadesBoundingsVertices != VertexBufferId.NULL)
     {
         MyHwBuffers.Destroy(m_cascadesBoundingsVertices);
         m_cascadesBoundingsVertices = VertexBufferId.NULL;
     }
 }
示例#5
0
 internal static void RemoveResource(InstancingId id)
 {
     if (Data[id.Index].VB != VertexBufferId.NULL)
     {
         MyHwBuffers.Destroy(Data[id.Index].VB);
         Data[id.Index].VB = VertexBufferId.NULL;
     }
 }
 public void Dispose()
 {
     if (m_stream != VertexBufferId.NULL)
     {
         MyHwBuffers.Destroy(m_stream);
         m_stream = VertexBufferId.NULL;
     }
 }
示例#7
0
 internal static void OnDeviceEnd()
 {
     if (m_IB != IndexBufferId.NULL)
     {
         MyHwBuffers.Destroy(m_IB);
         m_IB = IndexBufferId.NULL;
     }
 }
示例#8
0
 internal static void OnDeviceReset()
 {
     if (m_buffer != StructuredBufferId.NULL)
     {
         MyHwBuffers.Destroy(m_buffer);
         m_buffer = StructuredBufferId.NULL;
     }
     Init();
 }
示例#9
0
 internal void Dispose()
 {
     if (VB != VertexBufferId.NULL)
     {
         MyHwBuffers.Destroy(VB);
         VB = VertexBufferId.NULL;
     }
     m_capacity = 0;
 }
示例#10
0
        internal static void OnDeviceReset()
        {
            if (m_cubeIB != IndexBufferId.NULL)
            {
                MyHwBuffers.Destroy(m_cubeIB);
                m_cubeIB = IndexBufferId.NULL;
            }

            InitIB();
        }
示例#11
0
        internal void Release()
        {
            if (m_VB_positions != StructuredBufferId.NULL)
            {
                MyHwBuffers.Destroy(m_VB_positions);
                MyHwBuffers.Destroy(m_VB_rest);
                MyHwBuffers.Destroy(m_IB);
            }

            m_VB_positions = StructuredBufferId.NULL;
            m_VB_rest      = StructuredBufferId.NULL;
            m_IB           = StructuredBufferId.NULL;
        }
        internal unsafe void MoveToGPU()
        {
            var context = MyImmediateRC.RC.DeviceContext;

            if (m_tableDirty)
            {
                var array = m_instancingTable.Data;

                fixed(void *ptr = array)
                {
                    var intPtr = new IntPtr(ptr);

                    MyHwBuffers.ResizeAndUpdateStaticStructuredBuffer(ref m_indirectionBuffer, array.Length, sizeof(MyInstancingTableEntry), intPtr,
                                                                      "MyMergeInstancing/Tables", context);
                    m_SRVs[0] = m_indirectionBuffer.Srv;
                }

                m_tableDirty = false;
            }

            if (m_instancesDataDirty)
            {
                var array = m_perInstance.Data;

                fixed(void *ptr = array)
                {
                    var intPtr = new IntPtr(ptr);

                    if (m_instanceBuffer != StructuredBufferId.NULL && m_instanceBuffer.Capacity < array.Length)
                    {
                        MyHwBuffers.Destroy(m_instanceBuffer);
                        m_instanceBuffer = StructuredBufferId.NULL;
                        m_SRVs[1]        = null;
                    }
                    if (m_instanceBuffer == StructuredBufferId.NULL)
                    {
                        m_instanceBuffer = MyHwBuffers.CreateStructuredBuffer(array.Length, sizeof(MyPerInstanceData), true, intPtr, "MyMergeInstancing instances");
                        m_SRVs[1]        = m_instanceBuffer.Srv;
                    }
                    else
                    {
                        var mapping = MyMapping.MapDiscard(context, m_instanceBuffer.Buffer);
                        mapping.WriteAndPosition(array, 0, array.Length);
                        mapping.Unmap();
                    }
                }

                m_instancesDataDirty = false;
            }
        }
        internal void OnDeviceReset()
        {
            if (m_indirectionBuffer != StructuredBufferId.NULL)
            {
                MyHwBuffers.Destroy(m_indirectionBuffer);
                MyHwBuffers.Destroy(m_instanceBuffer);
            }

            m_indirectionBuffer = StructuredBufferId.NULL;
            m_instanceBuffer    = StructuredBufferId.NULL;
            Array.Clear(m_SRVs, 0, m_SRVs.Length);

            m_tableDirty         = true;
            m_instancesDataDirty = true;
        }
示例#14
0
 internal void ReleaseBuffers()
 {
     if (IB != IndexBufferId.NULL)
     {
         MyHwBuffers.Destroy(IB);
         IB = IndexBufferId.NULL;
     }
     if (VB != null)
     {
         foreach (var vb in VB)
         {
             //vb.Dispose();
             MyHwBuffers.Destroy(vb);
         }
         VB = null;
     }
 }
        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();
        }
示例#16
0
        unsafe static void InitBillboardsIndexBuffer()
        {
            if (m_IB != IndexBufferId.NULL)
            {
                MyHwBuffers.Destroy(m_IB);
            }

            uint[] indices = new uint[MAX_BILLBOARDS_SIZE * 6];
            for (int i = 0; i < MAX_BILLBOARDS_SIZE; i++)
            {
                indices[i * 6 + 0] = (uint)(i * 4 + 0);
                indices[i * 6 + 1] = (uint)(i * 4 + 1);
                indices[i * 6 + 2] = (uint)(i * 4 + 2);
                indices[i * 6 + 3] = (uint)(i * 4 + 0);
                indices[i * 6 + 4] = (uint)(i * 4 + 2);
                indices[i * 6 + 5] = (uint)(i * 4 + 3);
            }

            fixed(uint *ptr = indices)
            {
                m_IB = MyHwBuffers.CreateIndexBuffer(MAX_BILLBOARDS_SIZE * 6, SharpDX.DXGI.Format.R32_UInt, BindFlags.IndexBuffer, ResourceUsage.Immutable, new IntPtr(ptr), "MyBillboardRenderer");
            }
        }
        internal unsafe static void InitBillboardsIndexBuffer(int billboardsLimit)
        {
            if (m_IB != IndexBufferId.NULL)
            {
                MyHwBuffers.Destroy(m_IB);
            }

            uint[] indices = new uint[billboardsLimit * 6];
            for (int i = 0; i < billboardsLimit; i++)
            {
                indices[i * 6 + 0] = (uint)(i * 4 + 0);
                indices[i * 6 + 1] = (uint)(i * 4 + 1);
                indices[i * 6 + 2] = (uint)(i * 4 + 2);
                indices[i * 6 + 3] = (uint)(i * 4 + 0);
                indices[i * 6 + 4] = (uint)(i * 4 + 2);
                indices[i * 6 + 5] = (uint)(i * 4 + 3);
            }

            fixed(uint *ptr = indices)
            {
                m_IB = MyHwBuffers.CreateIndexBuffer(MaxBillboards * 6, SharpDX.DXGI.Format.R32_UInt, BindFlags.IndexBuffer, ResourceUsage.Immutable, new IntPtr(ptr));
            }
        }
示例#18
0
        internal unsafe void MoveToGPU()
        {
            var context = MyImmediateRC.RC.Context;

            if (m_tablesDirty)
            {
                var array = m_instancingTable.Data;

                fixed(void *ptr = array)
                {
                    var intPtr = new IntPtr(ptr);

                    if (m_indirectionBuffer != StructuredBufferId.NULL && m_indirectionBuffer.Capacity < array.Length)
                    {
                        MyHwBuffers.Destroy(m_indirectionBuffer);
                        m_indirectionBuffer = StructuredBufferId.NULL;
                        m_SRVs[0]           = null;
                    }
                    if (m_indirectionBuffer == StructuredBufferId.NULL)
                    {
                        m_indirectionBuffer = MyHwBuffers.CreateStructuredBuffer(array.Length, sizeof(MyInstancingTableEntry), false, intPtr);
                        m_SRVs[0]           = m_indirectionBuffer.Srv;
                    }
                    else
                    {
                        context.UpdateSubresource(new DataBox(intPtr, array.Length * sizeof(MyInstancingTableEntry), 0), m_indirectionBuffer.Buffer);
                    }
                }

                m_tablesDirty = false;
            }

            if (m_instancesDataDirty)
            {
                var array = m_perInstance.Data;

                fixed(void *ptr = array)
                {
                    var intPtr = new IntPtr(ptr);

                    if (m_instanceBuffer != StructuredBufferId.NULL && m_instanceBuffer.Capacity < array.Length)
                    {
                        MyHwBuffers.Destroy(m_instanceBuffer);
                        m_instanceBuffer = StructuredBufferId.NULL;
                        m_SRVs[1]        = null;
                    }
                    if (m_instanceBuffer == StructuredBufferId.NULL)
                    {
                        m_instanceBuffer = MyHwBuffers.CreateStructuredBuffer(array.Length, sizeof(MyPerInstanceData), true, intPtr);
                        m_SRVs[1]        = m_instanceBuffer.Srv;
                    }
                    else
                    {
                        var mapping = MyMapping.MapDiscard(context, m_instanceBuffer.Buffer);
                        mapping.stream.Write(intPtr, 0, array.Length * sizeof(MyPerInstanceData));
                        mapping.Unmap();
                    }
                }

                m_instancesDataDirty = false;
            }
        }
 internal void Close()
 {
     MyHwBuffers.Destroy(vbuffer);
 }