[mono-android] Initializing depth buffer for OpenGL 2.0 ES in MonoDroid
Kestutis Tauckela
kestutis.tauckela at gmail.com
Tue Mar 15 17:03:45 EDT 2011
Hi,
I would like to use MonoDroid/OpenGL 2.0 ES with depth buffer. From what
I've learned I need to override 'protected override void
CreateFrameBuffer()' in my child class of AndroidGameView class. In that
function, calling 'GLContextVersion = GLContextVersion.Gles2_0;' and
'base.CreateFrameBuffer();' will init frame buffer, render buffer and
graphics context. The problem is that there is no depth buffer. All my
attempts to attach a depth buffer failed. I was looking at MonoTouch, WebGL
examples and some OpenGL ES websites - with no success. My attempts to
create frame buffer from scratch failed even more spectacularly as I could
not create graphics context and no information on the web as to where or how
to get WindowInfo class.
Does anyone know any working example of MonoDroid OpenGL 2.0 ES with depth
buffer? Or maybe you could hint me how to init it properly.
Here are my attempts:
// 1. Working OpenGL 2.0 ES, but no depth buffer code. No fall back to 1.X
as I don't need that.
protected override void CreateFrameBuffer()
{
GLContextVersion = GLContextVersion.Gles2_0;
base.CreateFrameBuffer();
}
// 2. Failed attempt to attach depth buffer:
protected override void CreateFrameBuffer()
{
GLContextVersion = GLContextVersion.Gles2_0;
base.CreateFrameBuffer();
int nDepthBufferID = -1;
GL.GenRenderbuffers(1, ref nDepthBufferID);
GL.BindRenderbuffer(All.Renderbuffer, nDepthBufferID);
GL.RenderbufferStorage(All.Renderbuffer, All.DepthComponent16, 800,
480); // <- Don't know where to get real size from.
GL.FramebufferRenderbuffer(All.Framebuffer, All.DepthAttachment,
All.Renderbuffer, nDepthBufferID); // Does not work if Framebuffer is
bound to 0.
}
// 3. Failed attempt to create frame buffer from cratch:
protected override void CreateFrameBuffer()
{
GLContextVersion = GLContextVersion.Gles2_0;
int nFrameBufferID = -1;
GL.GenFramebuffers(1, ref nFrameBufferID);
GL.BindFramebuffer(All.Framebuffer, nFrameBufferID);
int nViewBufferID = -1;
GL.GenRenderbuffers(1, ref nViewBufferID);
GL.BindRenderbuffer(All.Renderbuffer, nViewBufferID);
GL.RenderbufferStorage(All.Renderbuffer, All.Rgb565, 800, 480); // <-
Don't know where to get real size from.
int nDepthBufferID = -1;
GL.GenRenderbuffers(1, ref nDepthBufferID);
GL.BindRenderbuffer(All.Renderbuffer, nDepthBufferID);
GL.RenderbufferStorage(All.Renderbuffer, All.DepthComponent16, 800,
480); // <- Don't know where to get real size from.
GL.FramebufferRenderbuffer(All.Framebuffer, All.DepthAttachment,
All.Renderbuffer, nDepthBufferID); // Works as frame buffer is not 0.
Log.Info("Example", string.Format("Frame buffer status: {0}",
GL.CheckFramebufferStatus(All.Framebuffer).ToString())); // <- All good
here, but it will crash on my attempt to render.
}
Thanks,
Kestutis Tauckela
http://www.outlanderstudios.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/mailman/private/monodroid/attachments/20110315/e852334e/attachment.html
More information about the Monodroid
mailing list