示例#1
0
        internal unsafe static InstancingId Create(uint GID, MyRenderInstanceBufferType type, string debugName)
        {
            var id = new InstancingId {
                Index = Instancings.Allocate()
            };

            Instancings.Data[id.Index] = new MyInstancingInfo
            {
                Type      = type,
                DebugName = debugName
            };

            MyArrayHelpers.Reserve(ref Data, id.Index + 1);
            Data[id.Index] = new MyInstancingData {
                VB = VertexBufferId.NULL
            };

            if (type == MyRenderInstanceBufferType.Cube)
            {
                Instancings.Data[id.Index].Layout = MyVertexLayouts.GetLayout(new MyVertexInputComponent(MyVertexInputComponentType.CUBE_INSTANCE, 2, MyVertexInputComponentFreq.PER_INSTANCE));
                Instancings.Data[id.Index].Stride = sizeof(MyVertexFormatCubeInstance);
            }
            else
            {
                Instancings.Data[id.Index].Layout = MyVertexLayouts.GetLayout(new MyVertexInputComponent(MyVertexInputComponentType.GENERIC_INSTANCE, 2, MyVertexInputComponentFreq.PER_INSTANCE));
                Instancings.Data[id.Index].Stride = sizeof(MyVertexFormatGenericInstance);
            }

            Debug.Assert(!IdIndex.ContainsKey(GID), "Creating instance with ID that already exists!");
            IdIndex.Add(GID, id);

            return(id);
        }
        internal unsafe static InstancingId Create(uint GID, MyRenderInstanceBufferType type, string debugName)
        {
            var id = new InstancingId { Index = Instancings.Allocate() };

            Instancings.Data[id.Index] = new MyInstancingInfo
            {
                Type = type,
                DebugName = debugName
            };

            MyArrayHelpers.Reserve(ref Data, id.Index + 1);
            Data[id.Index] = new MyInstancingData
            {
                VB = VertexBufferId.NULL
            };

            if(type == MyRenderInstanceBufferType.Cube)
            {
                Instancings.Data[id.Index].Layout = MyVertexLayouts.GetLayout(new MyVertexInputComponent(MyVertexInputComponentType.CUBE_INSTANCE, 2, MyVertexInputComponentFreq.PER_INSTANCE));
                Instancings.Data[id.Index].Stride = sizeof(MyVertexFormatCubeInstance);
            }
            else
            {
                Instancings.Data[id.Index].Layout = MyVertexLayouts.GetLayout(new MyVertexInputComponent(MyVertexInputComponentType.GENERIC_INSTANCE, 2, MyVertexInputComponentFreq.PER_INSTANCE));
                Instancings.Data[id.Index].Stride = sizeof(MyVertexFormatGenericInstance);
            }

            IdIndex[GID] = id;

            return id;
        }
        internal unsafe void Init(MyRenderInstanceBufferType type)
        {
            if (type == MyRenderInstanceBufferType.Cube)
            {
                m_input  = m_input.Append(MyVertexInputComponentType.CUBE_INSTANCE, 2, MyVertexInputComponentFreq.PER_INSTANCE);
                m_stride = sizeof(MyVertexFormatCubeInstance);
            }
            else if (type == MyRenderInstanceBufferType.Generic)
            {
                m_input  = m_input.Append(MyVertexInputComponentType.GENERIC_INSTANCE, 2, MyVertexInputComponentFreq.PER_INSTANCE);
                m_stride = sizeof(MyVertexFormatGenericInstance);
            }

            m_type = type;
        }
        internal unsafe void Init(MyRenderInstanceBufferType type)
        {
            Debug.Assert(type != MyRenderInstanceBufferType.Invalid, "Invalid instance buffer type!");
            if (type == MyRenderInstanceBufferType.Cube)
            {
                m_input = m_input.Append(MyVertexInputComponentType.CUBE_INSTANCE, 2, MyVertexInputComponentFreq.PER_INSTANCE);
                m_stride = sizeof(MyVertexFormatCubeInstance);
            }
            else if (type == MyRenderInstanceBufferType.Generic)
            {
                m_input = m_input.Append(MyVertexInputComponentType.GENERIC_INSTANCE, 2, MyVertexInputComponentFreq.PER_INSTANCE);
                m_stride = sizeof(MyVertexFormatGenericInstance);
            }

            m_type = type;
        }
示例#5
0
        internal override void Construct()
        {
            base.Construct();
            Type = MyActorComponentEnum.Instancing;

            MyUtils.Init(ref m_owners);
            m_owners.Clear();

            MyUtils.Init(ref m_ID);
            m_ID.Clear();

            VB         = VertexBufferId.NULL;
            m_input    = MyVertexInputLayout.Empty;
            m_stride   = -1;
            m_type     = MyRenderInstanceBufferType.Invalid;
            m_capacity = -1;
        }
        internal override void Construct()
        {
            base.Construct();
            Type = MyActorComponentEnum.Instancing;

            MyUtils.Init(ref m_owners);
            m_owners.Clear();

            MyUtils.Init(ref m_ID);
            m_ID.Clear();

            VB = VertexBufferId.NULL;
            m_input = MyVertexInputLayout.Empty;
            m_stride = -1;
            m_type = MyRenderInstanceBufferType.Invalid;
            m_capacity = -1;
        }
示例#7
0
        internal unsafe void Construct(MyRenderInstanceBufferType type)
        {
            m_capacity = 0;

            m_input = MyVertexInputLayout.Empty;

            if (type == MyRenderInstanceBufferType.Cube)
            {
                m_input.Append(MyVertexInputComponentType.CUBE_INSTANCE, 2, MyVertexInputComponentFreq.PER_INSTANCE);
                m_stride = sizeof(MyVertexFormatCubeInstance);
            }
            else if (type == MyRenderInstanceBufferType.Generic)
            {
                m_input.Append(MyVertexInputComponentType.GENERIC_INSTANCE, 2, MyVertexInputComponentFreq.PER_INSTANCE);
                m_stride = sizeof(MyVertexFormatGenericInstance);
            }

            m_type       = type;
            VertexBuffer = VertexBufferId.NULL;
        }
        internal unsafe void Construct(MyRenderInstanceBufferType type)
        {
            m_capacity = 0;

            m_input = MyVertexInputLayout.Empty;

            if(type == MyRenderInstanceBufferType.Cube)
            { 
                m_input.Append(MyVertexInputComponentType.CUBE_INSTANCE, 2, MyVertexInputComponentFreq.PER_INSTANCE);
                m_stride = sizeof(MyVertexFormatCubeInstance);
            }
            else if (type == MyRenderInstanceBufferType.Generic)
            {
                m_input.Append(MyVertexInputComponentType.GENERIC_INSTANCE, 2, MyVertexInputComponentFreq.PER_INSTANCE);
                m_stride = sizeof(MyVertexFormatGenericInstance);
            }

            m_type = type;
            VertexBuffer = VertexBufferId.NULL;
        }
        public unsafe MyRenderInstanceBuffer(uint id, string debugName, MyRenderInstanceBufferType type)
            : base(id, debugName, (RenderFlags)0)
        {
            Type = type;

            if(type == MyRenderInstanceBufferType.Cube)
            {
                VertexElements = new List<VertexElement>()
                {
                    new VertexElement(1, sizeof(byte) * 0, DeclarationType.UByte4N, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 1),
                    new VertexElement(1, sizeof(byte) * 4, DeclarationType.UByte4N, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 2),
                    new VertexElement(1, sizeof(byte) * 8, DeclarationType.UByte4N, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 3),
                    new VertexElement(1, sizeof(byte) * 12, DeclarationType.UByte4N, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 4),
                    new VertexElement(1, sizeof(byte) * 16, DeclarationType.UByte4N, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 5),
                    new VertexElement(1, sizeof(byte) * 20, DeclarationType.UByte4N, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 6),
                    new VertexElement(1, sizeof(byte) * 24, DeclarationType.UByte4N, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 7),
                    new VertexElement(1, sizeof(byte) * 28, DeclarationType.UByte4N, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 8),
                    new VertexElement(1, sizeof(byte) * 32, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 9),
                    new VertexElement(1, sizeof(byte) * 32 + sizeof(float) * 4, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 10),
                };

                Stride = Marshal.SizeOf(typeof(MyCubeInstanceData));
                Debug.Assert(Stride == 64, "Instance data stride has unexpected size");
            }
            else
            {
                VertexElements = new List<VertexElement>()
                {
                    new VertexElement(1, (short)(sizeof(HalfVector4) * 0), DeclarationType.HalfFour, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 1),
                    new VertexElement(1, (short)(sizeof(HalfVector4) * 1), DeclarationType.HalfFour, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 2),
                    new VertexElement(1, (short)(sizeof(HalfVector4) * 2), DeclarationType.HalfFour, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 3),
                    new VertexElement(1, (short)(sizeof(HalfVector4) * 3), DeclarationType.HalfFour, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 4),
                    new VertexElement(1, (short)(sizeof(HalfVector4) * 4), DeclarationType.HalfTwo, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 5),
                };

                Stride = Marshal.SizeOf(typeof(MyInstanceData));
                Debug.Assert(Stride == 40, "Instance data stride has unexpected size");
            }
            
        }
        public unsafe MyRenderInstanceBuffer(uint id, string debugName, MyRenderInstanceBufferType type)
            : base(id, debugName, (RenderFlags)0)
        {
            Type = type;

            if (type == MyRenderInstanceBufferType.Cube)
            {
                VertexElements = new List <VertexElement>()
                {
                    new VertexElement(1, sizeof(byte) * 0, DeclarationType.UByte4N, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 1),
                    new VertexElement(1, sizeof(byte) * 4, DeclarationType.UByte4N, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 2),
                    new VertexElement(1, sizeof(byte) * 8, DeclarationType.UByte4N, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 3),
                    new VertexElement(1, sizeof(byte) * 12, DeclarationType.UByte4N, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 4),
                    new VertexElement(1, sizeof(byte) * 16, DeclarationType.UByte4N, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 5),
                    new VertexElement(1, sizeof(byte) * 20, DeclarationType.UByte4N, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 6),
                    new VertexElement(1, sizeof(byte) * 24, DeclarationType.UByte4N, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 7),
                    new VertexElement(1, sizeof(byte) * 28, DeclarationType.UByte4N, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 8),
                    new VertexElement(1, sizeof(byte) * 32, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 9),
                    new VertexElement(1, sizeof(byte) * 32 + sizeof(float) * 4, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 10),
                };

                Stride = Marshal.SizeOf(typeof(MyCubeInstanceData));
                Debug.Assert(Stride == 64, "Instance data stride has unexpected size");
            }
            else
            {
                VertexElements = new List <VertexElement>()
                {
                    new VertexElement(1, (short)(sizeof(HalfVector4) * 0), DeclarationType.HalfFour, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 1),
                    new VertexElement(1, (short)(sizeof(HalfVector4) * 1), DeclarationType.HalfFour, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 2),
                    new VertexElement(1, (short)(sizeof(HalfVector4) * 2), DeclarationType.HalfFour, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 3),
                    new VertexElement(1, (short)(sizeof(HalfVector4) * 3), DeclarationType.HalfFour, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 4),
                    new VertexElement(1, (short)(sizeof(HalfVector4) * 4), DeclarationType.HalfTwo, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 5),
                };

                Stride = Marshal.SizeOf(typeof(MyInstanceData));
                Debug.Assert(Stride == 40, "Instance data stride has unexpected size");
            }
        }
示例#11
0
        public static uint CreateRenderInstanceBuffer(string debugName, MyRenderInstanceBufferType type)
        {
            var message = MessagePool.Get<MyRenderMessageCreateRenderInstanceBuffer>(MyRenderMessageEnum.CreateRenderInstanceBuffer);

            uint id = GetMessageId();
            message.ID = id;
            message.DebugName = debugName;
            message.Type = type;
            EnqueueMessage(message);

            return id;
        }
示例#12
0
        /// <param name="parentId">Parent of the instance. Currently used for debugging. May be left unassingned</param>
        public static uint CreateRenderInstanceBuffer(string debugName, MyRenderInstanceBufferType type, int parentId = -1)
        {
            var message = MessagePool.Get<MyRenderMessageCreateRenderInstanceBuffer>(MyRenderMessageEnum.CreateRenderInstanceBuffer);

            uint id = GetMessageId(ObjectType.InstanceBuffer);
            message.ID = id;
            message.ParentID = parentId == -1 ? MyRenderProxy.RENDER_ID_UNASSIGNED : (uint) parentId;
            message.DebugName = debugName;
            message.Type = type;
            EnqueueMessage(message);

            return id;
        }