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 RenderObject(Scene scene, string name, string src)
            : base(scene, name, src)
        {
            textures = new List<Texture>();

            pos = new Vector3(0, 0, 0);
            rot = new Quaternion(0, 0, 0, 1.0f);
            scale = new Vector3(1.0f, 1.0f, 1.0f);
            worldMatrix = new Matrix4();

            try
            {
                XmlDocument roXML = new XmlDocument();
                roXML.Load(src);

                foreach( XmlAttribute attrib in roXML.DocumentElement.Attributes )
                {
                    if( attrib.Name == "pos")
                    {
                        string[] values = attrib.Value.Split(',');
                        pos = new Vector3(Convert.ToSingle(values[0]), Convert.ToSingle(values[1]), Convert.ToSingle(values[2]));
                    }
                    else if( attrib.Name == "rot")
                    {
                        string[] values = attrib.Value.Split(',');
                        rot = new Quaternion(Convert.ToSingle(values[0]), Convert.ToSingle(values[1]), Convert.ToSingle(values[2]), Convert.ToSingle(values[3]));
                    }
                    else if( attrib.Name == "scale" )
                    {
                        string[] values = attrib.Value.Split(',');
                        scale = new Vector3(Convert.ToSingle(values[0]), Convert.ToSingle(values[1]), Convert.ToSingle(values[2]));
                    }
                    else if( attrib.Name == "update" )
                    {
                        updateCallback = Program.TheForm.FindUpdateFunction(attrib.Value);
                    }
                }

                foreach( XmlNode child in roXML.DocumentElement.ChildNodes )
                {
                    if( child.NodeType == XmlNodeType.Element )
                    {
                        string nodeName = child.Attributes.GetNamedItem("name").Value;
                        string nodeSrc = child.Attributes.GetNamedItem("src").Value;
                        if (child.Name == "mesh")
                        {
                            mesh = scene.GetMesh(nodeName, nodeSrc);
                        }
                        else if (child.Name == "shader")
                        {
                            shader = scene.GetShader(nodeName, nodeSrc);
                        }
                        else if (child.Name == "texture")
                        {
                            Texture tex = null;
                            if( nodeSrc == "frameBuffer" )
                            {
                                var depthTexture = false;
                                XmlAttribute dtAttr = (XmlAttribute)child.Attributes.GetNamedItem("depthTexture");
                                if( dtAttr != null )
                                    depthTexture = (dtAttr.Value == "true");

                                FrameBuffer fb = scene.GetFrameBuffer(nodeName, null);
                                if( fb != null )
                                {
                                    if( depthTexture )
                                        tex = fb.depthTexture;
                                    else
                                        tex = fb.colorTexture;
                                }
                            }
                            else
                            {
                                // Normal texture
                                tex = scene.GetTexture(nodeName, nodeSrc);
                            }

                            if( tex != null )
                            {
                                var texIndex = 0;
                                XmlAttribute index = (XmlAttribute)child.Attributes.GetNamedItem("texIndex");
                                if( index != null)
                                    texIndex = Convert.ToInt32(index.Value);

                                while (textures.Count <= texIndex)
                                    textures.Add(null);
                                textures[texIndex] = tex;
                            }
                        }
                        else if (child.Name == "shadowCamera")
                        {
                            shadowCamera = scene.GetCamera(nodeName, nodeSrc);
                        }
                    }
                }
            }
            catch(Exception e)
            {
                System.Windows.Forms.MessageBox.Show("Failed to load render object: " + src + "\r\n" + e.Message);
            }

            UpdateWorldMatrix();
        }