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.