Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of <see cref="VertexBuffer"/> class.
        /// </summary>
        /// <param name="context">Instance of an effect context</param>
        /// <param name="resourceId"></param>
        /// <param name="vertexBufferProperties"></param>
        /// <param name="customVertexBufferProperties"></param>
        public VertexBuffer(EffectContext context, System.Guid resourceId, SharpDX.Direct2D1.VertexBufferProperties vertexBufferProperties, CustomVertexBufferProperties customVertexBufferProperties) : base(IntPtr.Zero)
        {
            unsafe {
                var customVertexBufferPropertiesNative = new CustomVertexBufferProperties.__Native();
                customVertexBufferProperties.__MarshalTo(ref customVertexBufferPropertiesNative);

                var inputElementsNative = new InputElement.__Native[customVertexBufferProperties.InputElements.Length];
                try
                {
                    for (int i = 0; i < customVertexBufferProperties.InputElements.Length; i++)
                    {
                        customVertexBufferProperties.InputElements[i].__MarshalTo(ref inputElementsNative[i]);

                        fixed(void *pInputElements = inputElementsNative)
                        {
                            customVertexBufferPropertiesNative.InputElementsPointer = (IntPtr)pInputElements;
                            customVertexBufferPropertiesNative.ElementCount         = customVertexBufferProperties.InputElements.Length;
                            fixed(void *pInputSignature = customVertexBufferProperties.InputSignature)
                            {
                                customVertexBufferPropertiesNative.ShaderBufferSize = customVertexBufferProperties.InputSignature.Length;
                                customVertexBufferPropertiesNative.ShaderBufferWithInputSignature = (IntPtr)pInputSignature;

                                context.CreateVertexBuffer(vertexBufferProperties, resourceId, new IntPtr(&customVertexBufferPropertiesNative), this);
                            }
                        }
                }
                finally
                {
                    for (int i = 0; i < inputElementsNative.Length; i++)
                        inputElementsNative[i].__MarshalFree(); }
                }
            }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of <see cref="VertexBuffer"/> class.
        /// </summary>
        /// <param name="context">Instance of an effect context</param>
        /// <param name="resourceId"></param>
        /// <param name="vertexBufferProperties"></param>
        /// <param name="customVertexBufferProperties"></param>
        public VertexBuffer(EffectContext context, System.Guid resourceId, SharpDX.Direct2D1.VertexBufferProperties vertexBufferProperties, CustomVertexBufferProperties customVertexBufferProperties) : base(IntPtr.Zero)
        {
            unsafe {            
                var customVertexBufferPropertiesNative = new CustomVertexBufferProperties.__Native();
                customVertexBufferProperties.__MarshalTo(ref customVertexBufferPropertiesNative);

                var inputElementsNative = new InputElement.__Native[customVertexBufferProperties.InputElements.Length];
                try
                {
                    for (int i = 0; i < customVertexBufferProperties.InputElements.Length; i++)
                        customVertexBufferProperties.InputElements[i].__MarshalTo(ref inputElementsNative[i]);

                    fixed (void* pInputElements = inputElementsNative)
                    {
                        customVertexBufferPropertiesNative.InputElementsPointer = (IntPtr)pInputElements;
                        customVertexBufferPropertiesNative.ElementCount = customVertexBufferProperties.InputElements.Length;
                        fixed (void* pInputSignature = customVertexBufferProperties.InputSignature)
                        {
                            customVertexBufferPropertiesNative.ShaderBufferSize = customVertexBufferProperties.InputSignature.Length;
                            customVertexBufferPropertiesNative.ShaderBufferWithInputSignature = (IntPtr)pInputSignature;

                            context.CreateVertexBuffer(vertexBufferProperties, resourceId, new IntPtr(&customVertexBufferPropertiesNative), this);
                        }
                    }
                }
                finally
                {
                    for (int i = 0; i < inputElementsNative.Length; i++)
                        inputElementsNative[i].__MarshalFree();
                }
            }
        }