コード例 #1
0
 /// <summary>
 /// Swap the swapchain's next buffer with the front buffer.
 /// </summary>
 /// <param name="flags">The flags.</param>
 /// <param name="sourceRectangle">The source rectangle.</param>
 /// <param name="destinationRectangle">The destination rectangle.</param>
 /// <param name="windowOverride">The window override.</param>
 /// <returns>
 /// A <see cref="SharpDX.Result"/> object describing the result of the operation.
 /// </returns>
 /// <unmanaged>HRESULT IDirect3DDevice9Ex::PresentEx([In] const void* pSourceRect,[In] const void* pDestRect,[In] HWND hDestWindowOverride,[In] const RGNDATA* pDirtyRegion,[In] unsigned int dwFlags)</unmanaged>
 public void PresentEx(Present flags, RawRectangle sourceRectangle, RawRectangle destinationRectangle, IntPtr windowOverride)
 {
     unsafe
     {
         PresentEx(new IntPtr(&sourceRectangle), new IntPtr(&destinationRectangle), windowOverride, IntPtr.Zero, (int)flags);
     }
 }
コード例 #2
0
ファイル: Texture.cs プロジェクト: zmtzawqlp/SharpDX
 /// <summary>
 /// Adds a dirty region to a texture resource.
 /// </summary>
 /// <param name="dirtyRectRef">The dirty rect ref.</param>
 /// <returns>
 /// A <see cref="SharpDX.Result"/> object describing the result of the operation.
 /// </returns>
 /// <unmanaged>HRESULT IDirect3DTexture9::AddDirtyRect([In] const void* pDirtyRect)</unmanaged>
 public void AddDirtyRectangle(RawRectangle dirtyRectRef)
 {
     unsafe
     {
         AddDirtyRectangle(new IntPtr(&dirtyRectRef));
     }
 }
コード例 #3
0
        public static void DrawRectangle(this Device device, RawPoint pt, Size2 size, RawColorBGRA color)
        {
            var rect = new RawRectangle
            {
                Left   = pt.X,
                Top    = pt.Y,
                Right  = pt.X + size.Width,
                Bottom = pt.Y + size.Height
            };

            device.Clear(ClearFlags.Target, color, 0, 0, new[] { rect });

            //using (var line = new Line(device))
            //{
            //    line.Width = size.Height;
            //    //line.Antialias = true;
            //    var extraHeight = (float)size.Width / 2;
            //    var vertices = new[]
            //    {
            //        new RawVector2(pt.X, pt.Y + extraHeight),
            //        new RawVector2(pt.X + size.Width, pt.Y + extraHeight)
            //    };
            //    line.Draw(vertices, color);
            //}
        }
コード例 #4
0
        /// <summary>
        /// (Re)configures the class to a fresh state.
        /// </summary>
        private void Configure(int adapterIndex, int displayIndex)
        {
            Dispose(false);
            factory = new Factory1();
            adapter = factory.GetAdapter1(adapterIndex);
            device  = new Device(adapter);
            output  = adapter.GetOutput(displayIndex);
            screen  = output.QueryInterface <Output1>();
            bounds  = screen.Description.DesktopBounds;

            Texture2DDescription textureDesc = new Texture2DDescription
            {
                CpuAccessFlags    = CpuAccessFlags.Read,
                BindFlags         = BindFlags.None,
                Format            = Format.B8G8R8A8_UNorm,
                Width             = bounds.Right - bounds.Left,
                Height            = bounds.Bottom - bounds.Top,
                OptionFlags       = ResourceOptionFlags.None,
                MipLevels         = 1,
                ArraySize         = 1,
                SampleDescription = { Count = 1, Quality = 0 },
                Usage             = ResourceUsage.Staging
            };

            screenTexture = new Texture2D(device, textureDesc);
            ResetOutputDuplicator();
        }
コード例 #5
0
            private FramePars GetFrameParams(OutputDuplicateFrameInformation frameInfo)
            {
                FramePars frameParams = new FramePars();

                OutputDuplicateMoveRectangle[] moveRects = new OutputDuplicateMoveRectangle[0];
                RawRectangle[] dirtyRects = new RawRectangle[0];

                if (frameInfo.TotalMetadataBufferSize > 0) //if (frameInfo.AccumulatedFrames > 0)
                {
                    var bufferSizeBytes = frameInfo.TotalMetadataBufferSize;

                    int moveRectSizeBytes = GetMoveRects(bufferSizeBytes, out moveRects);
                    bufferSizeBytes -= moveRectSizeBytes;


                    int dirtyRectSizeBytes = GetDirtyRects(bufferSizeBytes, out dirtyRects);
                    bufferSizeBytes -= dirtyRectSizeBytes;

                    frameParams.DirtyRects = dirtyRects;
                    frameParams.MoveRects  = moveRects;
                    frameParams.FrameInfo  = frameInfo;
                }

                return(frameParams);
            }
        private FrameMetadata GetMetadata(Capture capture, OutputDuplicateFrameInformation frameInformation)
        {
            int totalBufferSize = frameInformation.TotalMetadataBufferSize;

            if (totalBufferSize == 0)
            {
                return(null);
            }

            var toReturn = new FrameMetadata();

            int actualLength;

            var moveBuffer = new OutputDuplicateMoveRectangle[totalBufferSize];

            capture.OutputDuplication.GetFrameMoveRects(moveBuffer.Length, moveBuffer, out actualLength);
            Array.Resize(ref moveBuffer, actualLength / Marshal.SizeOf(typeof(OutputDuplicateMoveRectangle)));
            toReturn.MoveRectangles = moveBuffer;

            var dirtyBuffer = new RawRectangle[totalBufferSize];

            capture.OutputDuplication.GetFrameDirtyRects(dirtyBuffer.Length, dirtyBuffer, out actualLength);
            Array.Resize(ref dirtyBuffer, actualLength / Marshal.SizeOf(typeof(RawRectangle)));
            toReturn.DirtyRectangles = dirtyBuffer;

            return(toReturn);
        }
コード例 #7
0
 /// <summary>
 /// Swap the swapchain's next buffer with the front buffer.
 /// </summary>
 /// <param name="flags">The flags.</param>
 /// <param name="sourceRectangle">The source rectangle.</param>
 /// <param name="destinationRectangle">The destination rectangle.</param>
 /// <param name="windowOverride">The window override.</param>
 /// <param name="dirtyRegionRGNData">The region.</param>
 /// <returns>
 /// A <see cref="SharpDX.Result"/> object describing the result of the operation.
 /// </returns>
 /// <unmanaged>HRESULT IDirect3DDevice9Ex::PresentEx([In] const void* pSourceRect,[In] const void* pDestRect,[In] HWND hDestWindowOverride,[In] const RGNDATA* pDirtyRegion,[In] unsigned int dwFlags)</unmanaged>
 public void PresentEx(Present flags, RawRectangle sourceRectangle, RawRectangle destinationRectangle, IntPtr windowOverride, IntPtr dirtyRegionRGNData)
 {
     unsafe
     {
         PresentEx(new IntPtr(&sourceRectangle), new IntPtr(&destinationRectangle), windowOverride, dirtyRegionRGNData, (int)flags);
     }
 }
コード例 #8
0
        private void RetrieveFrameMetadata(DesktopFrame frame)
        {
            if (frameInfo.TotalMetadataBufferSize > 0)
            {
                // Get moved regions
                int movedRegionsLength = 0;
                OutputDuplicateMoveRectangle[] movedRectangles = new OutputDuplicateMoveRectangle[frameInfo.TotalMetadataBufferSize];
                mDeskDupl.GetFrameMoveRects(movedRectangles.Length, movedRectangles, out movedRegionsLength);
                frame.MovedRegions = new MovedRegion[movedRegionsLength / Marshal.SizeOf(typeof(OutputDuplicateMoveRectangle))];
                for (int i = 0; i < frame.MovedRegions.Length; i++)
                {
                    frame.MovedRegions[i] = new MovedRegion()
                    {
                        Source      = new System.Drawing.Point(movedRectangles[i].SourcePoint.X, movedRectangles[i].SourcePoint.Y),
                        Destination = new System.Drawing.Rectangle(movedRectangles[i].DestinationRect.Left, movedRectangles[i].DestinationRect.Top, movedRectangles[i].DestinationRect.GetWidth(), movedRectangles[i].DestinationRect.GetHeight())
                    };
                }

                // Get dirty regions
                int            dirtyRegionsLength = 0;
                RawRectangle[] dirtyRectangles    = new RawRectangle[frameInfo.TotalMetadataBufferSize];
                mDeskDupl.GetFrameDirtyRects(dirtyRectangles.Length, dirtyRectangles, out dirtyRegionsLength);
                frame.UpdatedRegions = new System.Drawing.Rectangle[dirtyRegionsLength / Marshal.SizeOf(typeof(Rectangle))];
                for (int i = 0; i < frame.UpdatedRegions.Length; i++)
                {
                    frame.UpdatedRegions[i] = new System.Drawing.Rectangle(dirtyRectangles[i].Left, dirtyRectangles[i].Top, dirtyRectangles[i].GetWidth(), dirtyRectangles[i].GetHeight());
                }
            }
            else
            {
                frame.MovedRegions   = new MovedRegion[0];
                frame.UpdatedRegions = new System.Drawing.Rectangle[0];
            }
        }
コード例 #9
0
ファイル: CubeTexture.cs プロジェクト: zmtzawqlp/SharpDX
 /// <summary>
 /// Adds a dirty region to a cube texture resource.
 /// </summary>
 /// <param name="faceType">Type of the face.</param>
 /// <param name="dirtyRectRef">The dirty rect ref.</param>
 /// <returns>A <see cref="SharpDX.Result" /> object describing the result of the operation.</returns>
 /// <unmanaged>HRESULT IDirect3DCubeTexture9::AddDirtyRect([In] D3DCUBEMAP_FACES FaceType,[In] const void* pDirtyRect)</unmanaged>
 public void AddDirtyRectangle(SharpDX.Direct3D9.CubeMapFace faceType, RawRectangle dirtyRectRef)
 {
     unsafe
     {
         AddDirtyRectangle(faceType, new IntPtr(&dirtyRectRef));
     }
 }
コード例 #10
0
 private void DebugDrawRectOnScreenshot(Screenshot screenshot, RawRectangle rect, byte r, byte g, byte b)
 {
     // Draw top and bottom lines
     for (int y = rect.Top; y < rect.Bottom; y++)
     {
         int offset = y * screenshot.Stride;
         if (y == rect.Top || y + 1 == rect.Bottom)
         {
             for (int x = rect.Left; x < (rect.Right - 1); x++)
             {
                 int offset2 = x * 4;
                 screenshot.Buffer[offset + offset2]     = b;
                 screenshot.Buffer[offset + offset2 + 1] = g;
                 screenshot.Buffer[offset + offset2 + 2] = r;
             }
         }
         else
         {
             int offset2 = rect.Left * 4;
             screenshot.Buffer[offset + offset2]     = b;
             screenshot.Buffer[offset + offset2 + 1] = g;
             screenshot.Buffer[offset + offset2 + 2] = r;
             offset2 = (rect.Right - 1) * 4;
             screenshot.Buffer[offset + offset2]     = b;
             screenshot.Buffer[offset + offset2 + 1] = g;
             screenshot.Buffer[offset + offset2 + 2] = r;
         }
     }
 }
コード例 #11
0
 /// <summary>
 /// Copies the specified region from memory into the current bitmap.
 /// </summary>
 /// <remarks>
 /// This method does not update the size of the current bitmap. If the contents of the source bitmap do not fit in the current bitmap, this method fails. Also, note that this method does not perform format conversion; the two bitmap formats should match.  Passing this method invalid input, such as an invalid destination rectangle, can produce unpredictable results, such as a distorted image or device failure. Calling this method may cause the current batch to flush if the bitmap is active in the batch. If the batch that was flushed does not complete successfully, this method fails. However, this method does not clear the error state of the render target on which the batch was flushed. The failing <see cref="int"/> and tag state will be returned at the next call to {{EndDraw}} or {{Flush}}.
 /// </remarks>
 /// <param name="memory">The data to copy. </param>
 /// <param name="pitch">The stride, or pitch, of the source bitmap stored in srcData. The stride is the byte count of a scanline (one row of pixels in memory). The stride can be computed from the following formula: pixel width * bytes per pixel + memory padding. </param>
 /// <param name="destinationArea">In the current bitmap, the upper-left corner of the area to which the region specified by srcRect is copied. </param>
 /// <returns>If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. </returns>
 /// <msdn-id>dd371155</msdn-id>
 /// <unmanaged>HRESULT ID2D1Bitmap::CopyFromMemory([In, Optional] const D2D_RECT_U* dstRect,[In] const void* srcData,[In] unsigned int pitch)</unmanaged>
 /// <unmanaged-short>ID2D1Bitmap::CopyFromMemory</unmanaged-short>
 public void CopyFromMemory(byte[] memory, int pitch, RawRectangle destinationArea)
 {
     unsafe
     {
         fixed(void *pMemory = &memory[0]) CopyFromMemory(destinationArea, new IntPtr(pMemory), pitch);
     }
 }
コード例 #12
0
 /// <summary>
 /// Copies the specified region from memory into the current bitmap.
 /// </summary>
 /// <remarks>
 /// This method does not update the size of the current bitmap. If the contents of the source bitmap do not fit in the current bitmap, this method fails. Also, note that this method does not perform format conversion; the two bitmap formats should match.  Passing this method invalid input, such as an invalid destination rectangle, can produce unpredictable results, such as a distorted image or device failure. Calling this method may cause the current batch to flush if the bitmap is active in the batch. If the batch that was flushed does not complete successfully, this method fails. However, this method does not clear the error state of the render target on which the batch was flushed. The failing <see cref="int"/> and tag state will be returned at the next call to {{EndDraw}} or {{Flush}}.
 /// </remarks>
 /// <param name="memory">The data to copy. </param>
 /// <param name="pitch">The stride, or pitch, of the source bitmap stored in srcData. The stride is the byte count of a scanline (one row of pixels in memory). The stride can be computed from the following formula: pixel width * bytes per pixel + memory padding. </param>
 /// <param name="destinationArea">In the current bitmap, the upper-left corner of the area to which the region specified by srcRect is copied. </param>
 /// <returns>If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. </returns>
 /// <msdn-id>dd371155</msdn-id>
 /// <unmanaged>HRESULT ID2D1Bitmap::CopyFromMemory([In, Optional] const D2D_RECT_U* dstRect,[In] const void* srcData,[In] unsigned int pitch)</unmanaged>
 /// <unmanaged-short>ID2D1Bitmap::CopyFromMemory</unmanaged-short>
 public void CopyFromMemory <T>(T[] memory, int pitch, RawRectangle destinationArea) where T : struct
 {
     unsafe
     {
         CopyFromMemory(destinationArea, (IntPtr)Interop.Fixed(memory), pitch);
     }
 }
コード例 #13
0
        /// <inheritdoc/>
        public RawInt3 CalculateThreadgroups(RawRectangle outputRect)
        {
            RawInt3 result;

            CalculateThreadgroups_(outputRect, out result.X, out result.Y, out result.Z);
            return(result);
        }
コード例 #14
0
        /// <summary>
        /// Measures the specified sprite.
        /// </summary>
        /// <param name="sprite">Pointer to an <see cref="SharpDX.Direct3D9.Sprite"/> object that contains the string. Can be <c>null</c>, in which case Direct3D will render the string with its own sprite object. To improve efficiency, a sprite object should be specified if DrawText is to be called more than once in a row.</param>
        /// <param name="text"><para>Pointer to a string to draw. If the Count parameter is -1, the string must be null-terminated.</para></param>
        /// <param name="rect"><para>Pointer to a <see cref="RawRectangle"/> structure that contains the rectangle, in logical coordinates, in which the text is to be formatted. The coordinate value of the rectangle's right side must be greater than that of its left side. Likewise, the coordinate value of the bottom must be greater than that of the top.</para></param>
        /// <param name="drawFlags"><para>Specifies the method of formatting the text. It can be any combination of the following values:</para>  ValueMeaning <list> <item><term>DT_BOTTOM</term></item> </list>  <para>Justifies the text to the bottom of the rectangle. This value must be combined with DT_SINGLELINE.</para>  <list> <item><term>DT_CALCRECT</term></item> </list>  <para>Determines the width and height of the rectangle. If there are multiple lines of text, DrawText uses the width of the rectangle pointed to by the pRect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text but does not draw the text.</para>  <list> <item><term>DT_CENTER</term></item> </list>  <para>Centers text horizontally in the rectangle.</para>  <list> <item><term>DT_EXPANDTABS</term></item> </list>  <para>Expands tab characters. The default number of characters per tab is eight.</para>  <list> <item><term>DT_LEFT</term></item> </list>  <para>Aligns text to the left.</para>  <list> <item><term>DT_NOCLIP</term></item> </list>  <para>Draws without clipping. DrawText is somewhat faster when DT_NOCLIP is used.</para>  <list> <item><term>DT_RIGHT</term></item> </list>  <para>Aligns text to the right.</para>  <list> <item><term>DT_RTLREADING</term></item> </list>  <para>Displays text in right-to-left reading order for bidirectional text when a Hebrew or Arabic font is selected. The default reading order for all text is left-to-right.</para>  <list> <item><term>DT_SINGLELINE</term></item> </list>  <para>Displays text on a single line only. Carriage returns and line feeds do not break the line.</para>  <list> <item><term>DT_TOP</term></item> </list>  <para>Top-justifies text.</para>  <list> <item><term>DT_VCENTER</term></item> </list>  <para>Centers text vertically (single line only).</para>  <list> <item><term>DT_WORDBREAK</term></item> </list>  <para>Breaks words. Lines are automatically broken between words if a word would extend past the edge of the rectangle specified by the pRect parameter. A carriage return/line feed sequence also breaks the line.</para>   <para>?</para></param>
        /// <param name="textHeight">The height of the formatted text but does not draw the text.</param>
        /// <returns>Determines the width and height of the rectangle. If there are multiple lines of text, this function uses the width of the rectangle pointed to by the rect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, this method modifies the right side of the rectangle so that it bounds the last character in the line. </returns>
        public unsafe RawRectangle MeasureText(Sprite sprite, string text, RawRectangle rect, FontDrawFlags drawFlags, out int textHeight)
        {
            // DT_CALCRECT
            int whiteColor = -1;

            textHeight = DrawText(sprite, text, text.Length, new IntPtr(&rect), ((int)drawFlags) | 0x400, *(RawColorBGRA *)&whiteColor);
            return(rect);
        }
コード例 #15
0
        public void RenderText(string text, RawRectangle rect, RawColorBGRA color)
        {
            var s = _Engine.DefaultSprite;

            s.Begin();
            _Font.DrawText(s, text, rect, FontDrawFlags.Left, color);
            s.End();
        }
コード例 #16
0
        public unsafe RawRectangle RSGetScissorRect()
        {
            int numRects = 1;
            var rect     = new RawRectangle();

            RSGetScissorRects(ref numRects, (IntPtr)Unsafe.AsPointer(ref rect));
            return(rect);
        }
コード例 #17
0
ファイル: Texture.cs プロジェクト: zmtzawqlp/SharpDX
 /// <summary>
 /// Locks a rectangle on a texture resource.
 /// </summary>
 /// <param name="level">The level.</param>
 /// <param name="rectangle">The rectangle.</param>
 /// <param name="flags">The flags.</param>
 /// <returns>
 /// A <see cref="DataRectangle"/> describing the region locked.
 /// </returns>
 /// <unmanaged>HRESULT IDirect3DTexture9::LockRect([In] D3DCUBEMAP_FACES FaceType,[In] unsigned int Level,[In] D3DLOCKED_RECT* pLockedRect,[In] const void* pRect,[In] D3DLOCK Flags)</unmanaged>
 public DataRectangle LockRectangle(int level, RawRectangle rectangle, SharpDX.Direct3D9.LockFlags flags)
 {
     unsafe
     {
         LockedRectangle lockedRect;
         LockRectangle(level, out lockedRect, new IntPtr(&rectangle), flags);
         return(new DataRectangle(lockedRect.PBits, lockedRect.Pitch));
     }
 }
            private void InitInternal()
            {
                var factory = new Factory1();

                Adapter[] adapters = factory.Adapters;

                var toDispose = new HashSet <IDisposable>
                {
                    factory
                };

                _screenFound = false;

                foreach (Adapter adapter in adapters)
                {
                    toDispose.Add(adapter);
                    foreach (Output output in adapter.Outputs)
                    {
                        toDispose.Add(output);

                        OutputDescription outputDescription = output.Description;

                        if (_screenFound || !outputDescription.IsAttachedToDesktop || outputDescription.DeviceName.Trim('\0') != ScreenName)
                        {
                            continue;
                        }

                        RawRectangle desktopBounds = outputDescription.DesktopBounds;
                        _desktopBounds = desktopBounds;
                        var textureDescription = new Texture2DDescription
                        {
                            CpuAccessFlags    = CpuAccessFlags.Read,
                            BindFlags         = BindFlags.None,
                            Format            = Format.B8G8R8A8_UNorm,
                            Width             = desktopBounds.Right - desktopBounds.Left,
                            Height            = desktopBounds.Bottom - desktopBounds.Top,
                            OptionFlags       = ResourceOptionFlags.None,
                            MipLevels         = 1,
                            ArraySize         = 1,
                            SampleDescription = { Count = 1, Quality = 0 },
                            Usage             = ResourceUsage.Staging
                        };

                        _device = new Device(adapter);

                        var output1 = output.QueryInterface <Output1>();
                        _outputDuplication = output1.DuplicateOutput(_device);
                        _texture           = new Texture2D(_device, textureDescription);
                        _initialized       = true;
                        _screenFound       = true;
                    }
                }
                foreach (var disposable in toDispose)
                {
                    disposable.Dispose();
                }
            }
コード例 #19
0
        public SpriteResource MakeSprite(RawRectangle rect)
        {
            var resource = new SpriteResource(this, rect);

            if (Container != null)
            {
                resource.UpdateDevice(Container);
            }
            return(resource);
        }
コード例 #20
0
 /// <summary>
 /// Swap the swapchain's next buffer with the front buffer.
 /// </summary>
 /// <param name="flags">The flags.</param>
 /// <param name="sourceRectangle">The source rectangle.</param>
 /// <param name="destinationRectangle">The destination rectangle.</param>
 /// <param name="windowOverride">The window override.</param>
 /// <param name="region">The region.</param>
 /// <returns>
 /// A <see cref="SharpDX.Result"/> object describing the result of the operation.
 /// </returns>
 /// <unmanaged>HRESULT IDirect3DDevice9Ex::PresentEx([In] const void* pSourceRect,[In] const void* pDestRect,[In] HWND hDestWindowOverride,[In] const RGNDATA* pDirtyRegion,[In] unsigned int dwFlags)</unmanaged>
 public void PresentEx(Present flags, RawRectangle sourceRectangle, RawRectangle destinationRectangle, IntPtr windowOverride, Region region)
 {
     unsafe
     {
         var graphics  = Graphics.FromHwnd(windowOverride);
         var regionPtr = region.GetHrgn(graphics);
         graphics.Dispose();
         PresentEx(new IntPtr(&sourceRectangle), new IntPtr(&destinationRectangle), windowOverride, regionPtr, (int)flags);
     }
 }
コード例 #21
0
ファイル: DXSprite.cs プロジェクト: ImmutableGlitch/Anathena
            /// <summary>
            /// Initializes a new instance of the <see cref="Sprite" /> struct
            /// </summary>
            /// <param name="sourceRect"></param>
            /// <param name="destRect"></param>
            /// <param name="color"></param>
            public Sprite(RawRectangle sourceRect, RawRectangle destRect, RawColor4 color)
            {
                this.SourceRectangle = sourceRect;
                this.DestRectangle   = destRect;
                this.Color           = color;

                this.Z     = 0.0f;
                this.Angle = 0.0f;
                this.Scale = 1.0f;
            }
コード例 #22
0
ファイル: Texture.cs プロジェクト: zmtzawqlp/SharpDX
 /// <summary>
 /// Locks a rectangle on a texture resource.
 /// </summary>
 /// <param name="level">The level.</param>
 /// <param name="rectangle">The rectangle.</param>
 /// <param name="flags">The flags.</param>
 /// <param name="stream">The stream pointing to the locked region.</param>
 /// <returns>
 /// A <see cref="DataRectangle"/> describing the region locked.
 /// </returns>
 /// <unmanaged>HRESULT IDirect3DTexture9::LockRect([In] D3DCUBEMAP_FACES FaceType,[In] unsigned int Level,[In] D3DLOCKED_RECT* pLockedRect,[In] const void* pRect,[In] D3DLOCK Flags)</unmanaged>
 public DataRectangle LockRectangle(int level, RawRectangle rectangle, SharpDX.Direct3D9.LockFlags flags, out DataStream stream)
 {
     unsafe
     {
         LockedRectangle lockedRect;
         LockRectangle(level, out lockedRect, new IntPtr(&rectangle), flags);
         stream = new DataStream(lockedRect.PBits, lockedRect.Pitch * GetLevelDescription(level).Height, true, (flags & LockFlags.ReadOnly) == 0);
         return(new DataRectangle(lockedRect.PBits, lockedRect.Pitch));
     }
 }
コード例 #23
0
ファイル: DxCapture.cs プロジェクト: tony-jang/NextCapture
 private Rectangle RawToRectangle(RawRectangle rawRect)
 {
     return(new Rectangle()
     {
         X = rawRect.Left,
         Y = rawRect.Top,
         Width = rawRect.Right - rawRect.Left,
         Height = rawRect.Bottom - rawRect.Top
     });
 }
コード例 #24
0
        /// <summary>
        /// Draws formatted text.
        /// </summary>
        /// <param name="sprite"><para>Pointer to an <see cref="SharpDX.Direct3D9.Sprite"/> object that contains the string. Can be <c>null</c>, in which case Direct3D will render the string with its own sprite object. To improve efficiency, a sprite object should be specified if DrawText is to be called more than once in a row.</para></param>
        /// <param name="text"><para>Pointer to a string to draw. If the Count parameter is -1, the string must be null-terminated.</para></param>
        /// <param name="rect"><para>Pointer to a <see cref="RawRectangle"/> structure that contains the rectangle, in logical coordinates, in which the text is to be formatted. The coordinate value of the rectangle's right side must be greater than that of its left side. Likewise, the coordinate value of the bottom must be greater than that of the top.</para></param>
        /// <param name="drawFlags"><para>Specifies the method of formatting the text. It can be any combination of the following values:</para>  ValueMeaning <list> <item><term>DT_BOTTOM</term> </item></list>  <para>Justifies the text to the bottom of the rectangle. This value must be combined with DT_SINGLELINE.</para>  <list> <item><term>DT_CALCRECT</term></item> </list>  <para>Determines the width and height of the rectangle. If there are multiple lines of text, DrawText uses the width of the rectangle pointed to by the pRect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text but does not draw the text.</para>  <list> <item><term>DT_CENTER</term></item> </list>  <para>Centers text horizontally in the rectangle.</para>  <list> <item><term>DT_EXPANDTABS</term></item> </list>  <para>Expands tab characters. The default number of characters per tab is eight.</para>  <list> <item><term>DT_LEFT</term></item> </list>  <para>Aligns text to the left.</para>  <list> <item><term>DT_NOCLIP</term></item> </list>  <para>Draws without clipping. DrawText is somewhat faster when DT_NOCLIP is used.</para>  <list> <item><term>DT_RIGHT</term></item> </list>  <para>Aligns text to the right.</para>  <list> <item><term>DT_RTLREADING</term></item> </list>  <para>Displays text in right-to-left reading order for bidirectional text when a Hebrew or Arabic font is selected. The default reading order for all text is left-to-right.</para>  <list> <item><term>DT_SINGLELINE</term></item> </list>  <para>Displays text on a single line only. Carriage returns and line feeds do not break the line.</para>  <list> <item><term>DT_TOP</term></item> </list>  <para>Top-justifies text.</para>  <list> <item><term>DT_VCENTER</term></item> </list>  <para>Centers text vertically (single line only).</para>  <list> <item><term>DT_WORDBREAK</term></item> </list>  <para>Breaks words. Lines are automatically broken between words if a word would extend past the edge of the rectangle specified by the pRect parameter. A carriage return/line feed sequence also breaks the line.</para>   <para>?</para></param>
        /// <param name="color"><para>Color of the text. For more information, see <see cref="RawColor4"/>.</para></param>
        /// <returns>If the function succeeds, the return value is the height of the text in logical units. If DT_VCENTER or DT_BOTTOM is specified, the return value is the offset from pRect (top to the bottom) of the drawn text. If the function fails, the return value is zero.</returns>
        /// <remarks>
        /// The parameters of this method are very similar to those of the GDI DrawText function.This method supports both ANSI and Unicode strings.This method must be called inside a  BeginScene ... EndScene block. The only exception is when an application calls DrawText with DT_CALCRECT to calculate the size of a given block of text.Unless the DT_NOCLIP format is used, this method clips the text so that it does not appear outside the specified rectangle. All formatting is assumed to have multiple lines unless the DT_SINGLELINE format is specified.If the selected font is too large for the rectangle, this method does not attempt to substitute a smaller font.This method supports only fonts whose escapement and orientation are both zero.
        /// </remarks>
        /// <unmanaged>int ID3DXFont::DrawTextW([In] ID3DXSprite* pSprite,[In] const wchar_t* pString,[In] int Count,[In] void* pRect,[In] unsigned int Format,[In] D3DCOLOR Color)</unmanaged>
        public unsafe int DrawText(SharpDX.Direct3D9.Sprite sprite, string text, RawRectangle rect, FontDrawFlags drawFlags, RawColorBGRA color)
        {
            int value = DrawText(sprite, text, text.Length, new IntPtr(&rect), (int)drawFlags, color);

            if (value == 0)
            {
                throw new SharpDXException("Draw failed");
            }
            return(value);
        }
コード例 #25
0
ファイル: DXSprite.cs プロジェクト: ImmutableGlitch/Anathena
        public void Draw(RawRectangle destinationRectangle, RawRectangle sourceRectangle, RawColor4 color, Single scale = 1.0f, Single angle = 0f, Single z = 0f)
        {
            Sprite sprite = new Sprite(sourceRectangle, destinationRectangle, color)
            {
                Scale = scale,
                Angle = angle,
                Z     = z
            };

            this.SpriteList.Add(sprite);
        }
コード例 #26
0
        /// <summary>
        /// Get the array of {{scissor rectangles}} bound to the {{rasterizer stage}}.
        /// </summary>
        /// <returns>An array of scissor rectangles (see <see cref="RawRectangle"/>).</returns>
        /// <unmanaged>void RSGetScissorRects([InOut] int* NumRects,[Out, Buffer, Optional] D3D10_RECT* pRects)</unmanaged>
        public RawRectangle[] GetScissorRectangles()
        {
            int numRects = 0;

            GetScissorRects(ref numRects, null);

            RawRectangle[] scissorRectangles = new RawRectangle[numRects];
            GetScissorRects(ref numRects, scissorRectangles);

            return(scissorRectangles);
        }
コード例 #27
0
        /// <summary>
        /// Binds a single scissor rectangle to the rasterizer stage.
        /// </summary>
        /// <param name="left">The left.</param>
        /// <param name="top">The top.</param>
        /// <param name="right">The right.</param>
        /// <param name="bottom">The bottom.</param>
        /// <remarks>
        /// <p>All scissor rects must be set atomically as one operation. Any scissor rects not defined by the call are disabled.</p><p>The scissor rectangles will only be used if ScissorEnable is set to true in the rasterizer state (see <strong><see cref="SharpDX.Direct3D11.RasterizerStateDescription"/></strong>).</p><p>Which scissor rectangle to use is determined by the SV_ViewportArrayIndex semantic output by a geometry shader (see shader semantic syntax). If a geometry shader does not make use of the SV_ViewportArrayIndex semantic then Direct3D will use the first scissor rectangle in the array.</p><p>Each scissor rectangle in the array corresponds to a viewport in an array of viewports (see <strong><see cref="SharpDX.Direct3D11.RasterizerStage.SetViewports"/></strong>).</p>
        /// </remarks>
        /// <msdn-id>ff476478</msdn-id>
        /// <unmanaged>void ID3D11DeviceContext::RSSetScissorRects([In] unsigned int NumRects,[In, Buffer, Optional] const void* pRects)</unmanaged>
        /// <unmanaged-short>ID3D11DeviceContext::RSSetScissorRects</unmanaged-short>
        public void SetScissorRectangle(int left, int top, int right, int bottom)
        {
            var rect = new RawRectangle()
            {
                Left = left, Top = top, Right = right, Bottom = bottom
            };

            unsafe
            {
                SetScissorRects(1, new IntPtr(&rect));
            }
        }
コード例 #28
0
        public RawRectangle[] GetDirtyRectangles()
        {
            RawRectangle[] rawRectBuffer = rawRectHelper.GetExistingBuffer();
            // First, try with our existing buffer. It may fail and make us increase the buffer size.
            int requiredRawRectSize = -1;

            try
            {
                duplicatedOutput.GetFrameDirtyRects(rawRectHelper.bufferSizeBytes, rawRectBuffer, out requiredRawRectSize);
            }
            catch (SharpDXException e)
            {
                if (e.ResultCode.Code != SharpDX.DXGI.ResultCode.MoreData.Result.Code)
                {
                    throw e;
                }
            }
            if (requiredRawRectSize == -1)
            {
                throw new Exception("GetFrameDirtyRects did not tell us the required buffer size");
            }

            if (requiredRawRectSize > rawRectHelper.bufferSizeBytes)
            {
                if (requiredRawRectSize % rawRectHelper.itemSize != 0)
                {
                    throw new Exception("requiredRawRectSize " + requiredRawRectSize + " is not divisible by " + rawRectHelper.itemSize);
                }

                // Increase buffer size and try again
                rawRectBuffer = rawRectHelper.GetLargerBuffer(requiredRawRectSize / rawRectHelper.itemSize);
                duplicatedOutput.GetFrameDirtyRects(rawRectHelper.bufferSizeBytes, rawRectBuffer, out requiredRawRectSize);

                if (requiredRawRectSize % rawRectHelper.itemSize != 0)
                {
                    throw new Exception("requiredRawRectSize " + requiredRawRectSize + " is not divisible by " + rawRectHelper.itemSize);
                }
            }
            int numDirtyRects = requiredRawRectSize / rawRectHelper.itemSize;

            RawRectangle[] retVal = new RawRectangle[numDirtyRects];
            for (int i = 0; i < numDirtyRects; i++)
            {
                retVal[i] = rawRectBuffer[i];
                //Logger.Info("DirtyRect ["
                //	+ rawRectBuffer[i].Left + ","
                //	+ rawRectBuffer[i].Top + ","
                //	+ rawRectBuffer[i].Right + ","
                //	+ rawRectBuffer[i].Bottom + "]");
            }
            return(retVal);
        }
コード例 #29
0
        public void MapOutputRectangleToInputRectangles(RawRectangle outputRect, RawRectangle[] inputRects)
        {
            int expansion = (int)Math.Round(constants.Amplitude);

            if (inputRects.Length != 1)
            {
                throw new ArgumentException("InputRects must be length of 1", "inputRects");
            }
            inputRects[0].Left   = outputRect.Left - expansion;
            inputRects[0].Top    = outputRect.Top - expansion;
            inputRects[0].Right  = outputRect.Right + expansion;
            inputRects[0].Bottom = outputRect.Bottom + expansion;
        }
コード例 #30
0
        /// <summary>
        /// Binds a set of scissor rectangles to the rasterizer stage. See <see cref="Render+states"/> to learn how to use it.
        /// </summary>
        /// <param name="scissorRectangles">The set of scissor rectangles to bind.</param>
        public unsafe void SetScissorRectangles(params Rectangle[] scissorRectangles)
        {
            if (scissorRectangles == null)
            {
                throw new ArgumentNullException("scissorRectangles");
            }
            var localScissorRectangles = new RawRectangle[scissorRectangles.Length];

            for (int i = 0; i < scissorRectangles.Length; i++)
            {
                localScissorRectangles[i] = new RawRectangle(scissorRectangles[i].X, scissorRectangles[i].Y, scissorRectangles[i].Right, scissorRectangles[i].Bottom);
            }
            NativeDeviceContext.Rasterizer.SetScissorRectangles(localScissorRectangles);
        }