如何在MonoGame Android上复制一块纹理?

时间:2014-05-26 08:12:50

标签: android opengl-es monogame texture2d

我使用此代码将一块纹理复制到另一个纹理,它在Windows上运行,但在Android上它没有。我该如何解决?

这是我的代码:

public int DerivationGraph(int SrcX, int SrcY, int Width, int Height, int SrcGraphHandle)
    {
        Texture2D originalTexture = _textureCache[SrcGraphHandle];
        Rectangle sourceRectangle = new Rectangle(SrcX, SrcY, Width, Height);

        Texture2D cropTexture = new Texture2D(GraphicsDevice, sourceRectangle.Width, sourceRectangle.Height);
        Color[] data = new Color[sourceRectangle.Width * sourceRectangle.Height];
        originalTexture.GetData(0, sourceRectangle, data, 0, data.Length);
        cropTexture.SetData(data);
        int nextIndex = textureIndex + 1;
        _textureCache[nextIndex] = cropTexture;

        textureIndex++;
        return textureIndex;
    }

1 个答案:

答案 0 :(得分:0)

我正在研究同样的事情,不幸的是,似乎使用源矩形的特定重载根本不起作用。根据我的发现,问题来自OpenGL ES-2.0,在视频内存加载后不支持读取。

来自MonoGame Develop分支的discussion

  

tomspilman于2013年2月19日发表评论

     

将纹理数据上传到视频内存后无法读回

这个特定的讨论是关于GetData()的iOS实现,但它提到了Android重载,并且有一个解决方法让它工作。

就我个人而言,我在Android上尝试了generic method for GetData(),它实际上确实有效。但是,source rectangle method不会使用OpenGL ES 1.1或2.0返回任何数据。

获取整个纹理数据可能是您唯一的解决方案。