GetData() error creating framebuffer

Posted by Lelezeus on Game Development See other posts from Game Development or by Lelezeus
Published on 2013-09-15T15:00:30Z Indexed on 2013/11/05 10:15 UTC
Read the original article Hit count: 340

Filed under:
|
|
|
|

I'm currently porting a game written in C# with XNA library to Android with Monogame. I have a Texture2D and i'm trying to get an array of uint in this way:

Texture2d textureDeform = game.Content.Load<Texture2D>("Texture/terrain");
uint[] pixelDeformData = new uint[textureDeform.Width * textureDeform.Height];
textureDeform.GetData(pixelDeformData, 0, textureDeform.Width * textureDeform.Height);

I get the following exception:

System.Exception: Error creating framebuffer: Zero at Microsoft.Xna.Framework.Graphics.Texture2D.GetTextureData (Int32 ThreadPriorityLevel) [0x00000] in :0

I found that the problem is in private byte[] GetTextureData(int ThreadPriorityLevel) creating the framebuffer:

private byte[] GetTextureData(int ThreadPriorityLevel)
{
            int framebufferId = -1;
            int renderBufferID = -1;

            GL.GenFramebuffers(1, ref framebufferId);  // framebufferId is still -1 , why can't be created?
            GraphicsExtensions.CheckGLError();
            GL.BindFramebuffer(All.Framebuffer, framebufferId);
            GraphicsExtensions.CheckGLError();
            //renderBufferIDs = new int[currentRenderTargets];
            GL.GenRenderbuffers(1, ref renderBufferID);
            GraphicsExtensions.CheckGLError();

            // attach the texture to FBO color attachment point
            GL.FramebufferTexture2D(All.Framebuffer, All.ColorAttachment0,
                                    All.Texture2D, this.glTexture, 0);
            GraphicsExtensions.CheckGLError();

            // create a renderbuffer object to store depth info
            GL.BindRenderbuffer(All.Renderbuffer, renderBufferID);
            GraphicsExtensions.CheckGLError();
            GL.RenderbufferStorage(All.Renderbuffer, All.DepthComponent24Oes,
                                   Width, Height);
            GraphicsExtensions.CheckGLError();

            // attach the renderbuffer to depth attachment point
            GL.FramebufferRenderbuffer(All.Framebuffer, All.DepthAttachment,
                                       All.Renderbuffer, renderBufferID);
            GraphicsExtensions.CheckGLError();

            All status = GL.CheckFramebufferStatus(All.Framebuffer);

            if (status != All.FramebufferComplete)
                throw new Exception("Error creating framebuffer: " + status);

... 
} 

The frameBufferId is still -1, seems that framebuffer could not be generated and I don't know why. Any help would be appreciated, thank you in advance.

© Game Development or respective owner

Related posts about XNA

Related posts about android