public FrameBuffer(Scene scene, string name, string src) : base(scene, name, src) { try { XmlDocument fbXML = new XmlDocument(); fbXML.Load(src); width = Convert.ToInt32(fbXML.DocumentElement.Attributes.GetNamedItem("width").Value); height = Convert.ToInt32(fbXML.DocumentElement.Attributes.GetNamedItem("height").Value); colorFormat = fbXML.DocumentElement.Attributes.GetNamedItem("colorFormat").Value; colorTexture = scene.GetTexture(name + "_color", null); colorTexture.width = width; colorTexture.height = height; colorTexture.Create(PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero); depthTexture = scene.GetTexture(name + "_depth", null); depthTexture.width = width; depthTexture.height = height; depthTexture.format = PixelInternalFormat.DepthComponent; depthTexture.Create(PixelFormat.DepthComponent, PixelType.UnsignedShort, IntPtr.Zero); GL.GenFramebuffers(1, out frameBuffer); GL.BindFramebuffer(FramebufferTarget.Framebuffer, frameBuffer); GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, colorTexture.glTexture, 0); GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, TextureTarget.Texture2D, depthTexture.glTexture, 0); GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0); } catch(Exception ) { System.Windows.Forms.MessageBox.Show("Failed to load framebuffer: " + src); } }
public Texture GetTexture(string name, string src) { for (var i = 0; i < textures.Count; i++) { if (textures[i].name == name) return textures[i]; } Texture tex = new Texture(this, name, src); textures.Add(tex); return tex; }