/// <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(); } } }
//EffectContext _effectContext; public override void Initialize(EffectContext effectContext, TransformGraph transformGraph) { //WARNING : as soon as TransformGraph.SetSingleTransformNode is called it chain calls the //SetDrawInformation via a callbac. Unfortunately this is too early because the code below //within this method is used to populate stateful data needed by the SetDrawInformation call. //transformGraph.SetSingleTransformNode(this); var path = Windows.ApplicationModel.Package.Current.InstalledLocation.Path; byte[] vertexShaderBytecode = NativeFile.ReadAllBytes(path + "\\WaveEffect.cso"); effectContext.LoadVertexShader(GUID_WaveVertexShader, vertexShaderBytecode); // Only generate the vertex buffer if it has not already been initialized. vertexBuffer = effectContext.FindVertexBuffer(GUID_WaveVertexBuffer); if (vertexBuffer == null) { //InitializeVertexBuffer(effectContext); var mesh = GenerateMesh(); // Updating geometry every time the effect is rendered can be costly, so it is // recommended that vertex buffer remain static if possible (which it is in this // sample effect). using (var stream = DataStream.Create(mesh, true, true)) { var vbProp = new VertexBufferProperties(1, VertexUsage.Static, stream); var cvbProp = new CustomVertexBufferProperties(vertexShaderBytecode, new[] { new InputElement("MESH_POSITION", 0, SharpDX.DXGI.Format.R32G32_Float,0,0), }, Utilities.SizeOf<Vector2>()); // The GUID is optional, and is provided here to register the geometry globally. // As mentioned above, this avoids duplication if multiple versions of the effect // are created. vertexBuffer = new VertexBuffer(effectContext, GUID_WaveVertexBuffer, vbProp, cvbProp); } } PrepareForRender(ChangeType.Properties|ChangeType.Context); transformGraph.SetSingleTransformNode(this); }
/// <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(); } } }