System.Windows.Interop.D3DImage.AddDirtyRect C# (CSharp) Méthode

AddDirtyRect() private méthode

private AddDirtyRect ( Int32Rect dirtyRect ) : void
dirtyRect Int32Rect
Résultat void
        public void AddDirtyRect(Int32Rect dirtyRect)
        {
            WritePreamble();

            if (_lockCount == 0)
            {
                throw new InvalidOperationException(SR.Get(SRID.Image_MustBeLocked));
            }

            if (_pInteropDeviceBitmap == null)
            {
                throw new InvalidOperationException(SR.Get(SRID.D3DImage_MustHaveBackBuffer));
            }

            dirtyRect.ValidateForDirtyRect("dirtyRect", PixelWidth, PixelHeight);
            if (dirtyRect.HasArea)
            {
                // Unmanaged code will make sure that the rect is well-formed
                HRESULT.Check(UnsafeNativeMethods.InteropDeviceBitmap.AddDirtyRect(
                    dirtyRect.X, 
                    dirtyRect.Y, 
                    dirtyRect.Width, 
                    dirtyRect.Height, 
                    _pInteropDeviceBitmap
                    ));
                    
                // We're now dirty, but we won't consider it a change until Unlock
                _isDirty = true;
                _isChangePending = true;
            }
        }

Usage Example

        /// <summary>
        /// The render by OpenGL.
        /// </summary>
        private void RenderGLToD3dImage(D3DImage image, int w, int h, Action rendering)
        {
            if (w == 0 || h == 0)
            {
                return;
            }
            this.glControl.MakeCurrent();

            // resize D3D/OpenGL Surface if need
            this.ResizeIfNeed(w, h);

            // OnRender may be called twice in the same frame. Only render the first time.
            if (image.IsFrontBufferAvailable)
            {
                // render to sharedSurface using OpenGL
                this.wgl.WglDXLockObjectsNV(wglHandleDevice, 1, singleWglHandleSharedSurfaceArray);
                GL.BindFramebuffer(FramebufferTarget.Framebuffer, fbo);
                GL.DrawBuffer((DrawBufferMode)FramebufferAttachment.ColorAttachment0);
                rendering();
                GL.Finish();
                this.wgl.WglDXUnlockObjectsNV(wglHandleDevice, 1, singleWglHandleSharedSurfaceArray);

                try
                {
                    image.Lock();
                    image.SetBackBuffer(D3DResourceType.IDirect3DSurface9, sharedSurface.NativePointer);
                    image.AddDirtyRect(new Int32Rect(0, 0, w, h));
                }
                catch (Exception ex)
                {
                    // ???
                    Console.WriteLine(ex.ToString());
                    this.device.ResetEx(ref this.presentparams);
                }
                finally
                {
                    image.Unlock();
                }
            }
        }