在DirectX9中翻转纹理(托管)

时间:2018-01-10 09:52:46

标签: textures flip managed-directx

我需要垂直或水平翻转纹理。我使用以下代码:

        //We are use textures Format.X8R8G8B8, so            
        int bytesPerPixel = 4;

        int pitch;
        GraphicsStream srcGs = srcTexture.LockRectangle ( 0, LockFlags.ReadOnly, out pitch );
        GraphicsStream dstGs = dstTexture.LockRectangle ( 0, LockFlags.None );

        for ( int y = 0; y < h; y++ )
            for ( int x = 0; x < w; x++ )
            {
                byte [ ] buffer = new byte[ bytesPerPixel ];
                srcGs.Seek ( y * pitch + x * bytesPerPixel, SeekOrigin.Begin );
                srcGs.Read ( buffer, 0, bytesPerPixel );
                if ( flag == FlipTextureFlags.Horizontal )
                    dstGs.Seek ( ( h - y ) * pitch + x * bytesPerPixel, SeekOrigin.Begin );
                else
                    dstGs.Seek ( y * pitch + ( w - x ) * bytesPerPixel, SeekOrigin.Begin );
                dstGs.Write ( buffer, 0, bytesPerPixel );
            }
        srcTexture.UnlockRectangle ( 0 );
        dstTexture.UnlockRectangle ( 0 );

代码效果很好,但是有很多纹理,它们的大小可以高达1200x2600。由于翻转是动态的,因此程序的性能会降低。还有其他方法可以翻转纹理吗?或者如何保持性能? (我不使用着色器)

0 个答案:

没有答案
相关问题