internal unsafe void RecordCommands(MyRenderableProxy proxy, MyFoliageStream stream, int voxelMatId,
                                            VertexShader vertexShader, InputLayout inputLayout,
                                            int materialIndex, int indexCount, int startIndex, int baseVertex)
        {
            if (stream.m_stream == null)
            {
                return;
            }

            //var worldMatrix = proxy.WorldMatrix;
            //worldMatrix.Translation = Vector3D.Zero;
            //MyObjectData objectData = proxy.ObjectData;
            //objectData.LocalMatrix = Matrix.Identity;

            var worldMat = proxy.WorldMatrix;
            //worldMat.Translation -= MyRender11.Environment.CameraPosition;

            MyObjectDataCommon objectData = proxy.CommonObjectData;

            objectData.LocalMatrix = worldMat;

            MyMapping mapping = MyMapping.MapDiscard(RC, proxy.ObjectBuffer);

            mapping.WriteAndPosition(ref proxy.VoxelCommonObjectData);
            mapping.WriteAndPosition(ref objectData);
            mapping.Unmap();

            RC.AllShaderStages.SetConstantBuffer(MyCommon.OBJECT_SLOT, proxy.ObjectBuffer);

            BindProxyGeometry(proxy, RC);

            RC.VertexShader.Set(vertexShader);
            RC.SetInputLayout(inputLayout);

            int offset = -1;

            if (!stream.Append)
            {
                offset        = 0;
                stream.Append = true;
            }

            RC.SetTarget(stream.m_stream, offset);
            RC.AllShaderStages.SetConstantBuffer(MyCommon.FOLIAGE_SLOT, MyCommon.FoliageConstants);

            float densityFactor = MyVoxelMaterials1.Table[voxelMatId].FoliageDensity * MyRender11.Settings.GrassDensityFactor;

            float zero = 0;

            mapping = MyMapping.MapDiscard(RC, MyCommon.FoliageConstants);
            mapping.WriteAndPosition(ref densityFactor);
            mapping.WriteAndPosition(ref materialIndex);
            mapping.WriteAndPosition(ref voxelMatId);
            mapping.WriteAndPosition(ref zero);
            mapping.Unmap();

            RC.DrawIndexed(indexCount, startIndex, baseVertex);
        }
        internal unsafe void RecordCommands(MyRenderableProxy proxy, MyFoliageStream stream, int voxelMatId,
            VertexShader vertexShader, InputLayout inputLayout,
            int materialIndex, int indexCount, int startIndex, int baseVertex)
        {
            if (stream.m_stream == VertexBufferId.NULL) return;

            //var worldMatrix = proxy.WorldMatrix;
            //worldMatrix.Translation = Vector3D.Zero;
            //MyObjectData objectData = proxy.ObjectData;
            //objectData.LocalMatrix = Matrix.Identity;

            var worldMat = proxy.WorldMatrix;
            //worldMat.Translation -= MyRender11.Environment.CameraPosition;

            MyObjectDataCommon objectData = proxy.CommonObjectData;
            objectData.LocalMatrix = worldMat;

            MyMapping mapping = MyMapping.MapDiscard(RC, proxy.ObjectBuffer);
            mapping.WriteAndPosition(ref proxy.VoxelCommonObjectData);
            mapping.WriteAndPosition(ref objectData);
            mapping.Unmap();

            RC.AllShaderStages.SetConstantBuffer(MyCommon.OBJECT_SLOT, proxy.ObjectBuffer);

            BindProxyGeometry(proxy, RC);

            RC.VertexShader.Set(vertexShader);
            RC.SetInputLayout(inputLayout);

            int offset = -1;
            if (!stream.Append)
            {
                offset = 0;
                stream.Append = true;
            }

            RC.SetTarget(stream.m_stream.Buffer, offset);
            RC.AllShaderStages.SetConstantBuffer(MyCommon.FOLIAGE_SLOT, MyCommon.FoliageConstants);

            float densityFactor = MyVoxelMaterials1.Table[voxelMatId].FoliageDensity * MyRender11.Settings.GrassDensityFactor;

            float zero = 0;
            mapping = MyMapping.MapDiscard(RC, MyCommon.FoliageConstants);
            mapping.WriteAndPosition(ref densityFactor);
            mapping.WriteAndPosition(ref materialIndex);
            mapping.WriteAndPosition(ref voxelMatId);
            mapping.WriteAndPosition(ref zero);
            mapping.Unmap();

            RC.DrawIndexed(indexCount, startIndex, baseVertex);
        }
        internal unsafe void RecordCommands(MyRenderableProxy proxy, MyFoliageStream stream, int voxelMatId,
                                            VertexShader vertexShader, InputLayout inputLayout,
                                            int materialIndex, int indexCount, int startIndex, int baseVertex)
        {
            //var worldMatrix = proxy.WorldMatrix;
            //worldMatrix.Translation = Vector3D.Zero;
            //MyObjectData objectData = proxy.ObjectData;
            //objectData.LocalMatrix = Matrix.Identity;

            var worldMat = proxy.WorldMatrix;
            //worldMat.Translation -= MyEnvironment.CameraPosition;

            MyObjectData objectData = proxy.ObjectData;

            objectData.LocalMatrix = worldMat;

            MyMapping mapping;

            mapping = MyMapping.MapDiscard(RC.Context, proxy.objectBuffer);
            void *ptr = &objectData;

            mapping.stream.Write(new IntPtr(ptr), 0, sizeof(MyObjectData));
            mapping.Unmap();

            RC.SetCB(MyCommon.OBJECT_SLOT, proxy.objectBuffer);

            BindProxyGeometry(proxy);

            RC.SetVS(vertexShader);
            RC.SetIL(inputLayout);

            if (!stream.m_append)
            {
                Context.StreamOutput.SetTarget(stream.m_stream.Buffer, 0);
                stream.m_append = true;
            }
            else
            {
                Context.StreamOutput.SetTarget(stream.m_stream.Buffer, -1);
            }

            RC.SetCB(MyCommon.FOLIAGE_SLOT, MyCommon.FoliageConstants);

            mapping = MyMapping.MapDiscard(Context, MyCommon.FoliageConstants);
            mapping.stream.Write(MyVoxelMaterials1.Table[voxelMatId].FoliageDensity);
            mapping.stream.Write((uint)materialIndex);
            mapping.stream.Write((uint)voxelMatId);
            mapping.Unmap();

            Context.DrawIndexed(indexCount, startIndex, baseVertex);
        }
        internal unsafe void RecordCommands(MyRenderableProxy proxy, MyFoliageStream stream, int voxelMatId,
            VertexShader vertexShader, InputLayout inputLayout,            
            int materialIndex, int indexCount, int startIndex, int baseVertex)
        {
            MyObjectData objectData = proxy.ObjectData;

            MyMapping mapping;
            mapping = MyMapping.MapDiscard(RC.Context, proxy.objectBuffer);
            void* ptr = &objectData;
            mapping.stream.Write(new IntPtr(ptr), 0, sizeof(MyObjectData));
            mapping.Unmap();

            RC.SetCB(MyCommon.OBJECT_SLOT, proxy.objectBuffer);

            BindProxyGeometry(proxy);

            RC.SetVS(vertexShader);
            RC.SetIL(inputLayout);

            if(!stream.m_append)
            {
                Context.StreamOutput.SetTarget(stream.m_stream.Buffer, 0);
                stream.m_append = true;
            }
            else
            {
                Context.StreamOutput.SetTarget(stream.m_stream.Buffer, -1);
            }

            RC.SetCB(MyCommon.FOLIAGE_SLOT, MyCommon.FoliageConstants);

            mapping = MyMapping.MapDiscard(Context, MyCommon.FoliageConstants);
            mapping.stream.Write(MyVoxelMaterials1.Table[voxelMatId].FoliageDensity);
            mapping.stream.Write((uint)materialIndex);
            mapping.stream.Write((uint)voxelMatId);
            mapping.Unmap();

            Context.DrawIndexed(indexCount, startIndex, baseVertex);
        }
        internal unsafe void RecordCommands(MyRenderableProxy proxy, MyFoliageStream stream, int voxelMatId,
            VertexShader vertexShader, InputLayout inputLayout,            
            int materialIndex, int indexCount, int startIndex, int baseVertex)
        {
            //var worldMatrix = proxy.WorldMatrix;
            //worldMatrix.Translation = Vector3D.Zero;
            //MyObjectData objectData = proxy.ObjectData;
            //objectData.LocalMatrix = Matrix.Identity;

            var worldMat = proxy.WorldMatrix;
            //worldMat.Translation -= MyEnvironment.CameraPosition;

            MyObjectData objectData = proxy.ObjectData;
            objectData.LocalMatrix = worldMat;

            MyMapping mapping;
            mapping = MyMapping.MapDiscard(RC.Context, proxy.ObjectBuffer);
            void* ptr = &objectData;
            mapping.stream.Write(new IntPtr(ptr), 0, sizeof(MyObjectData));
            mapping.Unmap();

            RC.SetCB(MyCommon.OBJECT_SLOT, proxy.ObjectBuffer);

            BindProxyGeometry(proxy);

            RC.SetVS(vertexShader);
            RC.SetIL(inputLayout);

            if(!stream.m_append)
            {
                Context.StreamOutput.SetTarget(stream.m_stream.Buffer, 0);
                stream.m_append = true;
            }
            else
            {
                Context.StreamOutput.SetTarget(stream.m_stream.Buffer, -1);
            }

            RC.SetCB(MyCommon.FOLIAGE_SLOT, MyCommon.FoliageConstants);

            mapping = MyMapping.MapDiscard(Context, MyCommon.FoliageConstants);
            mapping.stream.Write(MyVoxelMaterials1.Table[voxelMatId].FoliageDensity * MyRender11.Settings.GrassDensityFactor);
            mapping.stream.Write((uint)materialIndex);
            mapping.stream.Write((uint)voxelMatId);
            mapping.Unmap();

            Context.DrawIndexed(indexCount, startIndex, baseVertex);
        }