当前位置: 首页>>代码示例>>C#>>正文


C# Texture.GetSurfaceLevel方法代码示例

本文整理汇总了C#中SharpDX.Direct3D9.Texture.GetSurfaceLevel方法的典型用法代码示例。如果您正苦于以下问题:C# Texture.GetSurfaceLevel方法的具体用法?C# Texture.GetSurfaceLevel怎么用?C# Texture.GetSurfaceLevel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SharpDX.Direct3D9.Texture的用法示例。


在下文中一共展示了Texture.GetSurfaceLevel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetRenderTargetDX10

        public void SetRenderTargetDX10(SharpDX.Direct3D10.Texture2D renderTarget)
        {
            if (RenderTarget != null)
            {
                RenderTarget = null;

                base.Lock();
                base.SetBackBuffer(D3DResourceType.IDirect3DSurface9, IntPtr.Zero);
                base.Unlock();
            }

            if (renderTarget == null)
                return;

            if (!IsShareable(renderTarget))
                throw new ArgumentException("Texture must be created with ResourceOptionFlags.Shared");

            Format format = DX10ImageSource.TranslateFormat(renderTarget);
            if (format == Format.Unknown)
                throw new ArgumentException("Texture format is not compatible with OpenSharedResource");

            IntPtr handle = GetSharedHandle(renderTarget);
            if (handle == IntPtr.Zero)
                throw new ArgumentNullException("Handle");

            RenderTarget = new Texture(DX10ImageSource.D3DDevice, renderTarget.Description.Width, renderTarget.Description.Height, 1, Usage.RenderTarget, format, Pool.Default, ref handle);
            using (Surface surface = RenderTarget.GetSurfaceLevel(0))
            {
                base.Lock();
                base.SetBackBuffer(D3DResourceType.IDirect3DSurface9, surface.NativePointer);
                base.Unlock();
            }
        }
开发者ID:JonathanWouters,项目名称:LevelEditor,代码行数:33,代码来源:DX10ImageSource.cs

示例2: InitTexture

    private void InitTexture(BluRayAPI.OSDTexture item)
    {
      if (item.Width == 0 || item.Height == 0 || item.Texture == IntPtr.Zero)
      {
        FreeResources();
        return;
      }

      if (_combinedOsdTexture == null || _combinedOsdTexture.IsDisposed)
      {
        _combinedOsdTexture = new Texture(_device, _fullOsdSize.Width, _fullOsdSize.Height, 1, Usage.RenderTarget, FORMAT, Pool.Default);
        _combinedOsdSurface = _combinedOsdTexture.GetSurfaceLevel(0);

        _sprite = new Sprite(_device);

        Rectangle dstRect = new Rectangle(0, 0, _fullOsdSize.Width, _fullOsdSize.Height);
        _device.ColorFill(_combinedOsdSurface, dstRect, _transparentColor);
      }
    }
开发者ID:davinx,项目名称:MediaPortal-2,代码行数:19,代码来源:BluRayOSDRenderer.cs

示例3: SetBackBufferDX11

        public void SetBackBufferDX11(D3D11.Texture2D texture)
        {
            if (m_sharedTexture != null)
            {
                m_sharedTexture.Dispose();
                m_sharedTexture = null;
            }

            if (texture == null)
            {
                Lock();
                SetBackBuffer(D3DResourceType.IDirect3DSurface9, IntPtr.Zero);
                Unlock();
            }
            else
            {
                if (IsShareable(texture) == false)
                    throw new ArgumentException("Texture must be created with ResourceOptionFlags.Shared");

                D3D9.Format format = TranslateFormat(texture);
                if (format == D3D9.Format.Unknown)
                    throw new ArgumentException("Texture format is not compatible with OpenSharedResource");

                IntPtr handle = GetSharedHandle(texture);
                if (handle == IntPtr.Zero)
                    throw new ArgumentNullException("Handle");

                m_sharedTexture = new D3D9.Texture(s_device, texture.Description.Width, texture.Description.Height, 1,
                    D3D9.Usage.RenderTarget, format, D3D9.Pool.Default, ref handle);

                using (D3D9.Surface surface = m_sharedTexture.GetSurfaceLevel(0))
                {
                    Lock();
                    SetBackBuffer(D3DResourceType.IDirect3DSurface9, surface.NativePointer);
                    Unlock();
                }
            }
        }
开发者ID:Fulborg,项目名称:dwarrowdelf,代码行数:38,代码来源:D3DImageSharpDX.cs

示例4: D3D11Image

        /// <summary>
        /// Creates new instance of <see cref="D3D11Image"/> Associates an D3D11 render target with the current instance.
        /// </summary>
        /// <param name="device">A valid D3D9 DeviceEx.</param>
        /// <param name="renderTarget">A valid D3D11 render target. It must be created with the "Shared" flag.</param>
        public D3D11Image(DeviceEx device, Direct3D11.Texture2D renderTarget)
        {
            using (var resource = renderTarget.QueryInterface<DXGI.Resource>())
            {
                var handle = resource.SharedHandle;
                texture = new Texture(device,
                                      renderTarget.Description.Width,
                                      renderTarget.Description.Height,
                                      1,
                                      Usage.RenderTarget,
                                      Format.A8R8G8B8,
                                      Pool.Default,
                                      ref handle);
            }

            using (var surface = texture.GetSurfaceLevel(0))
            {
                textureSurfaceHandle = surface.NativePointer;
                TrySetBackbufferPointer(textureSurfaceHandle);
            }

            this.IsFrontBufferAvailableChanged += HandleIsFrontBufferAvailableChanged;
        }
开发者ID:chantsunman,项目名称:Toolkit,代码行数:28,代码来源:D3D11Image.cs

示例5: SetRenderTarget

        public void SetRenderTarget( SharpDX.Direct3D11.Texture2D target ) {
            if( renderTarget != null ) {
                renderTarget = null;

                base.Lock();
                base.SetBackBuffer( D3DResourceType.IDirect3DSurface9, IntPtr.Zero );
                base.Unlock();
            }

            if( target == null ) {
                return;
            }

            var format = Dx11ImageSource.TranslateFormat( target );
            var handle = GetSharedHandle( target );

            if ( !IsShareable( target ) ) {
                throw new ArgumentException( "Texture must be created with ResouceOptionFlags.Shared" );
            }

            if ( format == Format.Unknown ) {
                throw new ArgumentException( "Texture format is not compatible with OpenSharedResouce" );
            }

            if ( handle == IntPtr.Zero ) {
                throw new ArgumentException( "Invalid handle" );
            }

            renderTarget = new Texture( Dx11ImageSource.D3DDevice, target.Description.Width, target.Description.Height, 1, Usage.RenderTarget, format, Pool.Default, ref handle );

            using( var surface = renderTarget.GetSurfaceLevel( 0 ) ) {
                base.Lock();
                base.SetBackBuffer( D3DResourceType.IDirect3DSurface9, surface.NativePointer );
                base.Unlock();
            }
        }
开发者ID:Korhog,项目名称:D2dControl,代码行数:36,代码来源:Dx11ImageSource.cs

示例6: DrawItem

    public void DrawItem(BluRayAPI.OSDTexture item)
    {
      try
      {
        lock (_syncObj)
        {
          InitTexture(item);
          if (_combinedOsdSurface != null)
          {
            Rectangle sourceRect = new Rectangle(0, 0, item.Width, item.Height);
            Rectangle dstRect = new Rectangle(item.X, item.Y, item.Width, item.Height);

            using (Texture itemTexture = new Texture(item.Texture))
              _device.StretchRectangle(itemTexture.GetSurfaceLevel(0), sourceRect, _combinedOsdSurface, dstRect, TextureFilter.None);
          }
        }
      }
      catch (Exception ex)
      {
        BluRayPlayerBuilder.LogError(ex.ToString());
      }

      if (_onTextureInvalidated != null)
        _onTextureInvalidated();
    }
开发者ID:davinx,项目名称:MediaPortal-2,代码行数:25,代码来源:BluRayOSDRenderer.cs

示例7: DrawFullscreenQuad

 private void DrawFullscreenQuad(Texture texture, Texture renderTarget)
 {
     //set the render target.
     Surface savedRenderTarget = _graphics.GetRenderTarget(0);
     _graphics.SetRenderTarget(0, renderTarget.GetSurfaceLevel(0));
     DrawFullscreenQuad(texture);
     _graphics.SetRenderTarget(0, savedRenderTarget);
 }
开发者ID:tgjones,项目名称:meshellator,代码行数:8,代码来源:BlurComponent.cs

示例8: SetBackBuffer

        /// <summary>
        /// Sets the back buffer of the <see cref="D3D11Image"/>.
        /// </summary>
        /// <param name="texture">The Direct3D 11 texture to be used as the back buffer.</param>
        public void SetBackBuffer(Texture2D texture)
        {
            ThrowIfDisposed();

            var previousBackBuffer = _backBuffer;

            // Create shared texture on Direct3D 9 device.
            _backBuffer = _d3D9.GetSharedTexture(texture);
            if (_backBuffer != null)
            {
                // Set texture as new back buffer.
                using (Surface surface = _backBuffer.GetSurfaceLevel(0))
                {
                    Lock();
                    SetBackBuffer(D3DResourceType.IDirect3DSurface9, surface.NativePointer);
                    Unlock();
                }
            }
            else
            {
                // Reset back buffer.
                Lock();
                SetBackBuffer(D3DResourceType.IDirect3DSurface9, IntPtr.Zero);
                Unlock();                
            }

            if (previousBackBuffer != null)
                previousBackBuffer.Dispose();
        }
开发者ID:Nailz,项目名称:MonoGame-Samples,代码行数:33,代码来源:D3D11Image.cs

示例9: Draw

        public static void Draw(bool draw = true)
        {
            RenderTimeInMS += MyRenderConstants.RENDER_STEP_IN_MILLISECONDS;

            MyPerformanceCounter.PerCameraDrawWrite.Reset();

            UpdateInterpolationLag();
            
            GetRenderProfiler().StartProfilingBlock("ProcessMessages");
            ProcessMessageQueue();
            GetRenderProfiler().EndProfilingBlock();

            if (draw)
            {
                Texture rt = null;
                Texture dt = null;

                if (m_screenshot != null)
                {
                    m_renderSetup.CallerID = MyRenderCallerEnum.Main;

                    Viewport viewport = MyRenderCamera.Viewport;
                    m_sizeMultiplierForStrings = m_screenshot.SizeMultiplier;

                    UpdateScreenSize();
                    MyEnvironmentMap.Reset();

                    MyRenderCamera.ChangeFov(MyRenderCamera.FieldOfView); // Refresh projection
                    MyRenderCamera.UpdateCamera();
                    MyRender.SetDeviceViewport(MyRenderCamera.Viewport);

                    CreateRenderTargets();
                    m_renderSetup.ShadowRenderer = MyRender.GetShadowRenderer();
                    //We need depth n stencil because stencil is used for drawing hud
                    rt = new Texture(GraphicsDevice, (int)(MyRenderCamera.Viewport.Width), (int)(MyRenderCamera.Viewport.Height), 1, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);
                    dt = new Texture(GraphicsDevice, (int)(MyRenderCamera.Viewport.Width), (int)(MyRenderCamera.Viewport.Height), 1, Usage.DepthStencil, Format.D24S8, Pool.Default);
                    m_renderSetup.RenderTargets = new Texture[] { rt };
                    m_renderSetup.AspectRatio = MyRenderCamera.AspectRatio;
                    m_renderSetup.ProjectionMatrix = MyRenderCamera.ProjectionMatrix;

                    m_screenshot.DefaultSurface = rt.GetSurfaceLevel(0);
                    m_screenshot.DefaultDepth = dt.GetSurfaceLevel(0);

                    // To have render target with large size on device (screen.Draw calls MyCamera.EnableForward, which sets Viewport on device)
                    SetRenderTargets(m_renderSetup.RenderTargets, dt);
                    PushRenderSetupAndApply(m_renderSetup, ref m_backupRenderSetup);

                    m_backupRenderSetup.Viewport = viewport;
                }

                GetRenderProfiler().StartProfilingBlock("DrawMessageQueue");
                DrawMessageQueue();
                GetRenderProfiler().EndProfilingBlock();

                if (null != m_texturesToRender && m_texturesToRender.Count > 0)
                {
                    RenderColoredTextures();
                }

                if (m_screenshot != null)
                {                 
                    MyRender.PopRenderSetupAndRevert(m_backupRenderSetup);
                    
                    MyRender.TakeScreenshot("FinalScreen", GetScreenshotTexture(), Effects.MyEffectScreenshot.ScreenshotTechniqueEnum.Color);

                    var screen = m_screenshot;
                    m_screenshot = null; // Need to clear before SetRenderTarget(null, null)

                    SetRenderTarget(null, null);
                    MyRender.Blit(GetScreenshotTexture(), true, MyEffectScreenshot.ScreenshotTechniqueEnum.Color);

                    GetScreenshotTexture().Dispose();

                    screen.DefaultSurface.Dispose();
                    screen.DefaultDepth.Dispose();

                    rt.Dispose();
                    dt.Dispose();

                    MyRender.GraphicsDevice.Viewport = m_backupRenderSetup.Viewport.Value;
                    UpdateScreenSize();
                    MyRender.CreateRenderTargets();
                    MyEnvironmentMap.Reset();
                    RestoreDefaultTargets();
                    m_sizeMultiplierForStrings = Vector2.One;
                } 
            }

            GetRenderProfiler().StartProfilingBlock("ClearDrawMessages");
            ClearDrawMessages();
            GetRenderProfiler().EndProfilingBlock();

            if (m_spriteBatch != null)
                Debug.Assert(m_spriteBatch.ScissorStack.Empty);
        }
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:95,代码来源:MyRender-Draw.cs

示例10: BlitToMemory

		protected void BlitToMemory( BasicBox srcBox, PixelBox dst, BufferResources srcBufferResources, D3D9.Device d3d9Device )
		{
			// Decide on pixel format of temp surface
			PixelFormat tmpFormat = Format;
			if ( D3D9Helper.ConvertEnum( dst.Format ) != D3D9.Format.Unknown )
			{
				tmpFormat = dst.Format;
			}

			if ( srcBufferResources.Surface != null )
			{
				Debug.Assert( srcBox.Depth == 1 && dst.Depth == 1 );
				var srcDesc = srcBufferResources.Surface.Description;
				var temppool = D3D9.Pool.Scratch;

				// if we're going to try to use GetRenderTargetData, need to use system mem pool
				var tryGetRenderTargetData = false;
				if ( ( ( srcDesc.Usage & D3D9.Usage.RenderTarget ) != 0 ) && ( srcBox.Width == dst.Width ) &&
				     ( srcBox.Height == dst.Height ) && ( srcBox.Width == Width ) && ( srcBox.Height == Height ) &&
				     ( Format == tmpFormat ) )
				{
					tryGetRenderTargetData = true;
					temppool = D3D9.Pool.SystemMemory;
				}

				// Create temp texture
				var tmp = new D3D9.Texture( d3d9Device, dst.Width, dst.Height, 1, // 1 mip level ie topmost, generate no mipmaps
				                            0, D3D9Helper.ConvertEnum( tmpFormat ), temppool );

				var surface = tmp.GetSurfaceLevel( 0 );

				// Copy texture to this temp surface
				var srcRect = ToD3DRectangle( srcBox );
				var destRect = ToD3DRectangle( dst );

				// Get the real temp surface format
				var dstDesc = surface.Description;
				tmpFormat = D3D9Helper.ConvertEnum( dstDesc.Format );

				// Use fast GetRenderTargetData if we are in its usage conditions
				var fastLoadSuccess = false;
				if ( tryGetRenderTargetData )
				{
					var result = d3d9Device.GetRenderTargetData( srcBufferResources.Surface, surface );
					fastLoadSuccess = result.Success;
				}
				if ( !fastLoadSuccess )
				{
					var res = D3D9.Surface.FromSurface( surface, srcBufferResources.Surface, D3D9.Filter.Default, 0, srcRect, destRect );
					if ( res.Failure )
					{
						surface.SafeDispose();
						tmp.SafeDispose();
						throw new AxiomException( "D3D9.Surface.FromSurface failed in D3D9HardwarePixelBuffer.BlitToMemory" );
					}
				}

				// Lock temp surface and copy it to memory
				var lrect = surface.LockRectangle( D3D9.LockFlags.ReadOnly );

				// Copy it
				var locked = new PixelBox( dst.Width, dst.Height, dst.Depth, tmpFormat );
				FromD3DLock( locked, lrect );
				PixelConverter.BulkPixelConversion( locked, dst );
				surface.UnlockRectangle();
				// Release temporary surface and texture
				surface.SafeDispose();
				tmp.SafeDispose();
			}
			else if ( srcBufferResources.Volume != null )
			{
				// Create temp texture
				var tmp = new D3D9.VolumeTexture( d3d9Device, dst.Width, dst.Height, dst.Depth, 0, 0,
				                                  D3D9Helper.ConvertEnum( tmpFormat ), D3D9.Pool.Scratch );

				var surface = tmp.GetVolumeLevel( 0 );

				// Volume
				var ddestBox = ToD3DBoxExtent( dst );
				var dsrcBox = ToD3DBox( srcBox );

				var res = D3D9.Volume.FromVolume( surface, srcBufferResources.Volume, D3D9.Filter.Default, 0, dsrcBox, ddestBox );
				if ( res.Failure )
				{
					surface.SafeDispose();
					tmp.SafeDispose();
					throw new AxiomException( "D3D9.Surface.FromVolume failed in D3D9HardwarePixelBuffer.BlitToMemory" );
				}

				// Lock temp surface and copy it to memory
				var lbox = surface.LockBox( D3D9.LockFlags.ReadOnly ); // Filled in by D3D

				// Copy it
				var locked = new PixelBox( dst.Width, dst.Height, dst.Depth, tmpFormat );
				FromD3DLock( locked, lbox );
				PixelConverter.BulkPixelConversion( locked, dst );
				surface.UnlockBox();
				// Release temporary surface and texture
				surface.SafeDispose();
				tmp.SafeDispose();
//.........这里部分代码省略.........
开发者ID:ryan-bunker,项目名称:axiom3d,代码行数:101,代码来源:D3D9HardwarePixelBuffer.cs

示例11: SetRenderTargetDX10

		internal void SetRenderTargetDX10(global::SharpDX.Direct3D11.Texture2D renderTarget)
		{
			if (_renderTarget != null)
			{
				_renderTarget = null;

				Lock();
				SetBackBuffer(D3DResourceType.IDirect3DSurface9, IntPtr.Zero);
				Unlock();
			}

			if (renderTarget == null)
				return;

			if (!renderTarget.IsShareable())
				throw new ArgumentException("Texture must be created with ResourceOptionFlags.Shared");

			var format = renderTarget.GetTranslatedFormat();
			if (format == Format.Unknown)
				throw new ArgumentException("Texture format is not compatible with OpenSharedResource");

			var handle = renderTarget.GetSharedHandle();
			if (handle == IntPtr.Zero)
				throw new ArgumentException("Handle could not be retrieved");

			_renderTarget = new Texture(DeviceService.D3DDevice, 
				renderTarget.Description.Width, 
				renderTarget.Description.Height, 
				1, Usage.RenderTarget, format, 
				Pool.Default, ref handle);

			using (Surface surface = _renderTarget.GetSurfaceLevel(0))
			{
				Lock();
				SetBackBuffer(D3DResourceType.IDirect3DSurface9, surface.NativePointer);
				Unlock();
			}
		}
开发者ID:4ux-nbIx,项目名称:gemini,代码行数:38,代码来源:D3D11ImageSource.cs

示例12: SaveScreenshot

        public static void SaveScreenshot(Texture texture2D, string file)
        {      
            MyMwcLog.WriteLine("MyScreenshot.SaveTexture2D() - START");
            MyMwcLog.IncreaseIndent();

            Texture systemTex =  new Texture(MinerWars.AppCode.App.MyMinerGame.Static.GraphicsDevice, texture2D.GetLevelDescription(0).Width, texture2D.GetLevelDescription(0).Height, 0, Usage.None, Format.A8R8G8B8, Pool.SystemMemory);


            Surface sourceSurface = texture2D.GetSurfaceLevel(0);
            Surface destSurface = systemTex.GetSurfaceLevel(0);
            MinerWars.AppCode.App.MyMinerGame.Static.GraphicsDevice.GetRenderTargetData(sourceSurface, destSurface);
            sourceSurface.Dispose();
            destSurface.Dispose();

            texture2D = systemTex;

            try
            {
                MyMwcLog.WriteLine("File: " + file);

                MyFileSystemUtils.CreateFolderForFile(file);

                Stack<SharpDX.Rectangle> tiles = new Stack<SharpDX.Rectangle>();

                int tileWidth = texture2D.GetLevelDescription(0).Width;
                int tileHeight = texture2D.GetLevelDescription(0).Height;

                while (tileWidth > 3200)
                {
                    tileWidth /= 2;
                    tileHeight /= 2;
                }

                int widthOffset = 0;
                int heightOffset = 0;

                while (widthOffset < texture2D.GetLevelDescription(0).Width)
                {
                    while (heightOffset < texture2D.GetLevelDescription(0).Height)
                    {
                        tiles.Push(new SharpDX.Rectangle(widthOffset, heightOffset, tileWidth, tileHeight));
                        heightOffset += tileHeight;
                    }

                    heightOffset = 0;
                    widthOffset += tileWidth;
                }

                int sc = 0;
                while (tiles.Count > 0)
                {
                    SharpDX.Rectangle rect = tiles.Pop();

                    byte[] data = new byte[rect.Width * rect.Height * 4];
                    SharpDX.Rectangle rect2 = new SharpDX.Rectangle(rect.X, rect.Y, rect.Width, rect.Height);
                    //texture2D.GetData<byte>(0, rect2, data, 0, data.Length);
                    DataStream ds;
                    texture2D.LockRectangle(0, rect2, LockFlags.None, out ds); 

                    ds.Read(data, 0, data.Length);
                            /*
                    for (int i = 0; i < data.Length; i += 4)
                    {
                        //Swap ARGB <-> RGBA
                        byte b = data[i + 0];
                        byte g = data[i + 1];
                        byte r = data[i + 2];
                        byte a = data[i + 3];
                        data[i + 0] = r;  //Blue
                        data[i + 1] = g; //Green
                        data[i + 2] = b; //Red
                        data[i + 3] = a; //Alpha
                    }         */

                    ds.Seek(0, SeekOrigin.Begin);
                    ds.WriteRange(data);

                    texture2D.UnlockRectangle(0);

                    string filename = file.Replace(".png", "_" + sc.ToString("##00") + ".png");
                    using (Stream stream = File.Create(filename))
                    {        
                        System.Drawing.Bitmap image = new System.Drawing.Bitmap(rect.Width, rect.Height);

                        System.Drawing.Imaging.BitmapData imageData = image.LockBits(new System.Drawing.Rectangle(0,0,rect.Width, rect.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                        System.Runtime.InteropServices.Marshal.Copy(data, 0, imageData.Scan0, data.Length);

                        image.Save(stream, System.Drawing.Imaging.ImageFormat.Png);

                        image.UnlockBits(imageData);
                        image.Dispose();
                               
                        //texture2D.SaveAsPng(stream, texture2D.Width, texture2D.Height);
                        //BaseTexture.ToStream(texture2D, ImageFileFormat.Png);
                    }

                    sc++;
                    GC.Collect();
                }
            }
//.........这里部分代码省略.........
开发者ID:Bunni,项目名称:Miner-Wars-2081,代码行数:101,代码来源:MyScreenshot.cs

示例13: SetBackbuffer

        /// <summary>
        /// Associates an D3D11 render target with the current instance.
        /// </summary>
        /// <param name="renderTarget">An valid D3D11 render target. It must be created with the "Shared" flag.</param>
        internal void SetBackbuffer(Direct3D11.Texture2D renderTarget)
        {
            DisposedGuard();

            DisposeD3D9Backbuffer();

            using (var resource = renderTarget.QueryInterface<DXGI.Resource>())
            {
                var handle = resource.SharedHandle;
                texture = new Texture(device9,
                                      renderTarget.Description.Width,
                                      renderTarget.Description.Height,
                                      1,
                                      Usage.RenderTarget,
                                      Format.A8R8G8B8,
                                      Pool.Default,
                                      ref handle);
            }

            using (var surface = texture.GetSurfaceLevel(0))
                TrySetBackbufferPointer(surface.NativePointer);
        }
开发者ID:richardbang83,项目名称:SharpDX-1,代码行数:26,代码来源:SharpDXElement.cs

示例14: SaveScreenshot

        public static string SaveScreenshot(Texture tex, string file)
        {
            MyRender.Log.WriteLine("MyScreenshot.SaveTexture2D() - START");
            MyRender.Log.IncreaseIndent();

            string filename = null;

            using (Texture systemTex = new Texture(MyRender.GraphicsDevice, tex.GetLevelDescription(0).Width, tex.GetLevelDescription(0).Height, 1, Usage.None, Format.A8R8G8B8, Pool.SystemMemory))
            {
                string extension = Path.GetExtension(file);

                using (Surface sourceSurface = tex.GetSurfaceLevel(0))
                using (Surface destSurface = systemTex.GetSurfaceLevel(0))
                {
                    MyRender.GraphicsDevice.GetRenderTargetData(sourceSurface, destSurface);
                }
                
                try
                {
                    MyRender.Log.WriteLine("File: " + file);

                    Stack<SharpDX.Rectangle> tiles = new Stack<SharpDX.Rectangle>();

                    int tileWidth = systemTex.GetLevelDescription(0).Width;
                    int tileHeight = systemTex.GetLevelDescription(0).Height;

                    while (tileWidth > 3200)
                    {
                        tileWidth /= 2;
                        tileHeight /= 2;
                    }

                    int widthOffset = 0;
                    int heightOffset = 0;

                    while (widthOffset < systemTex.GetLevelDescription(0).Width)
                    {
                        while (heightOffset < systemTex.GetLevelDescription(0).Height)
                        {
                            tiles.Push(new SharpDX.Rectangle(widthOffset, heightOffset, widthOffset + tileWidth, heightOffset + tileHeight));
                            heightOffset += tileHeight;
                        }

                        heightOffset = 0;
                        widthOffset += tileWidth;
                    }

                    bool multipleTiles = tiles.Count > 1;

                    int sc = 0;
                    byte[] data = new byte[tileWidth * tileHeight * 4];

                    int sysTexWidth = systemTex.GetLevelDescription(0).Width;
                    int sysTexHeight = systemTex.GetLevelDescription(0).Height;
                    while (tiles.Count > 0)
                    {
                        SharpDX.Rectangle rect = tiles.Pop();
                        //texture2D.GetData<byte>(0, rect2, data, 0, data.Length);
                        DataStream ds;
                        //DataRectangle dr = texture2D.LockRectangle(0, rect2, LockFlags.ReadOnly, out ds);
                        DataRectangle dr = systemTex.LockRectangle(0, LockFlags.ReadOnly, out ds);

                        //we have to go line by line..
                        ds.Seek(rect.Y * sysTexWidth * 4, SeekOrigin.Begin);
                        int targetOffset = 0;

                        int linesCount = tileHeight;

                        int pixelsBefore = rect.X;
                        int pixelsAfter = sysTexWidth - tileWidth - rect.X;

                        while (linesCount-- > 0)
                        {
                            if (pixelsBefore > 0)
                                ds.Seek(pixelsBefore * 4, SeekOrigin.Current);
                            
                            ds.Read(data, targetOffset, tileWidth * 4);
                            targetOffset += tileWidth * 4;
                            
                            if (pixelsAfter > 0 && linesCount > 0)
                                ds.Seek(pixelsAfter * 4, SeekOrigin.Current);
                        }

                        systemTex.UnlockRectangle(0);
                        filename = file;

                        if (multipleTiles)
                        {
                            filename = file.Replace(extension, "_" + sc.ToString("##00") + extension);
                        }

                        using (var stream = MyFileSystem.OpenWrite(MyFileSystem.UserDataPath, filename))
                        {
                            using (System.Drawing.Bitmap image = new System.Drawing.Bitmap(tileWidth, tileHeight))
                            {
                                System.Drawing.Imaging.BitmapData imageData = image.LockBits(new System.Drawing.Rectangle(0, 0, tileWidth, tileHeight), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

                                System.Runtime.InteropServices.Marshal.Copy(data, 0, imageData.Scan0, data.Length);

                                if (extension == ".png")
//.........这里部分代码省略.........
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:101,代码来源:MyScreenshot.cs

示例15: SetRenderTargets

 public static void SetRenderTargets(Texture[] rts, Texture depth, SetDepthTargetEnum depthOp = SetDepthTargetEnum.NoChange)
 {
     if (rts == null)
     {
         RestoreDefaultTargets();
     }
     else
     {
         for (int i = 0; i < 3; i++)
         {
             if (i < rts.Length)
             {
                 Surface surface = rts[i].GetSurfaceLevel(0);
                 MyMinerGame.Static.GraphicsDevice.SetRenderTarget(i, surface);
                 surface.Dispose();
             }
             else
                 MyMinerGame.Static.GraphicsDevice.SetRenderTarget(i, null);
         }
         if (depth != null)
         {
             Surface surface = depth.GetSurfaceLevel(0);
             MyMinerGame.Static.GraphicsDevice.DepthStencilSurface = surface;
             surface.Dispose();
         }
         else if (depthOp == SetDepthTargetEnum.RestoreDefault)
         {
             MyMinerGame.Static.GraphicsDevice.DepthStencilSurface = DefaultDepth;
         }
             
         m_renderTargetsCount = rts.Length;
     }
 }                                    
开发者ID:Bunni,项目名称:Miner-Wars-2081,代码行数:33,代码来源:MyMinerGame.cs


注:本文中的SharpDX.Direct3D9.Texture.GetSurfaceLevel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。