Bind() public method

start to use this framebuffer.
public Bind ( FramebufferTarget target = FramebufferTarget.Framebuffer ) : void
target FramebufferTarget
return void
Example #1
0
        private Framebuffer CreateFramebuffer(int width, int height)
        {
            var texture = new Texture(TextureTarget.Texture2D,
                                      new NullImageFiller(width, height, GL.GL_RGBA, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE),
                                      new SamplerParameters(
                                          TextureWrapping.Repeat,
                                          TextureWrapping.Repeat,
                                          TextureWrapping.Repeat,
                                          TextureFilter.Linear,
                                          TextureFilter.Linear));

            texture.Initialize();
            this.BindingTexture = texture;
            Renderbuffer colorBuffer = Renderbuffer.CreateColorbuffer(width, height, GL.GL_RGBA);
            Renderbuffer depthBuffer = Renderbuffer.CreateDepthbuffer(width, height, DepthComponentType.DepthComponent24);
            var          framebuffer = new Framebuffer();

            framebuffer.Bind();
            framebuffer.Attach(colorBuffer);                         //0
            framebuffer.Attach(texture);                             //1
            framebuffer.Attach(depthBuffer);                         // special
            framebuffer.SetDrawBuffers(GL.GL_COLOR_ATTACHMENT0 + 1); // as in 1 in framebuffer.Attach(texture);//1
            framebuffer.CheckCompleteness();
            framebuffer.Unbind();
            return(framebuffer);
        }
Example #2
0
        /// <summary>
        /// Pick geometry at specified positon.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="geometryTypes"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <returns></returns>
        public PickedGeometry Pick(int x, int y, PickingGeometryTypes geometryTypes, int width, int height)
        {
            if (x < 0 || width <= x)
            {
                return(null);
            }
            if (y < 0 || height <= y)
            {
                return(null);
            }
            if (geometryTypes == 0)
            {
                return(null);
            }

            PickedGeometry pickedGeometry = null;

            Framebuffer framebuffer = GetPickingFramebuffer(width, height);

            framebuffer.Bind();
            {
                const float one = 1.0f;
                GL.Instance.ClearColor(one, one, one, one);
                GL.Instance.Clear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT);

                var arg = new PickingEventArgs(this.Scene, x, y, geometryTypes);
                this.RenderForPicking(this.Scene.RootNode, arg);

                bool dump = false;
                if (dump)
                {
                    var final = new Bitmap(width, height);
                    var data  = final.LockBits(new Rectangle(0, 0, width, height), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                    //glGetTexImage((uint)texture.Target, 0, GL_BGRA, GL_UNSIGNED_BYTE, data.Scan0);
                    GL.Instance.ReadPixels(0, 0, width, height, GL.GL_BGRA, GL.GL_UNSIGNED_BYTE, data.Scan0);
                    final.UnlockBits(data);
                    final.RotateFlip(RotateFlipType.Rotate180FlipX);
                    final.Save(string.Format("picking.dump.png"));
                }

                uint stageVertexId = ColorCodedPicking.ReadStageVertexId(x, y);

                pickedGeometry = SearchGeometry(stageVertexId, arg, this.Scene.RootNode);

                if (pickedGeometry != null)
                {
                    var      depth  = new float[1];
                    GCHandle pinned = GCHandle.Alloc(depth, GCHandleType.Pinned);
                    IntPtr   header = pinned.AddrOfPinnedObject();
                    // same with: IntPtr header = Marshal.UnsafeAddrOfPinnedArrayElement(array, 0);
                    GL.Instance.ReadPixels(x, y, 1, 1, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, header);
                    pinned.Free();

                    pickedGeometry.PickedPosition = new vec3(x, y, depth[0]);
                }
            }
            framebuffer.Unbind();

            return(pickedGeometry);
        }
Example #3
0
        /// <summary>
        /// A render context.
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public FBORenderContext(int width, int height, ContextGenerationParams parameters)
            : base(width, height, parameters)
        {
            Framebuffer framebuffer = CreateFramebuffer(width, height, parameters);

            framebuffer.Bind();
            this.framebuffer = framebuffer;
        }
Example #4
0
        /// <summary>
        /// Creates the render context provider. Must also create the OpenGL extensions.
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="bitDepth"></param>
        /// <returns></returns>
        public FBORenderContext(int width, int height, short bitDepth)
            : base(width, height, bitDepth)
        {
            Framebuffer framebuffer = CreateFramebuffer(width, height);
            framebuffer.Bind();
            this.framebuffer = framebuffer;

            this.dibSection = new DIBSection(this.DeviceContextHandle, width, height, bitDepth);
        }
Example #5
0
        private Framebuffer CreatePickFramebuffer(int width, int height)
        {
            var framebuffer = new Framebuffer(width, height);

            framebuffer.Bind();
            framebuffer.Attach(RenderbufferType.ColorBuffer);
            framebuffer.Attach(RenderbufferType.DepthBuffer);
            framebuffer.CheckCompleteness();
            framebuffer.Unbind();

            return(framebuffer);
        }
        private Framebuffer CreatePickFramebuffer(int width, int height)
        {
            Renderbuffer colorBuffer = Renderbuffer.CreateColorbuffer(width, height, GL.GL_RGBA);
            Renderbuffer depthBuffer = Renderbuffer.CreateDepthbuffer(width, height, DepthComponentType.DepthComponent24);
            var          framebuffer = new Framebuffer();

            framebuffer.Bind();
            framebuffer.Attach(colorBuffer);
            framebuffer.Attach(depthBuffer);
            framebuffer.CheckCompleteness();
            framebuffer.Unbind();

            return(framebuffer);
        }
        private Framebuffer CreateFramebuffer(int width, int height)
        {
            var framebuffer = new Framebuffer(width, height);

            framebuffer.Bind();
            Renderbuffer colorbuffer = framebuffer.Attach(RenderbufferType.ColorBuffer);      //0
            Texture      texture     = framebuffer.Attach(TextureAttachment.ColorAttachment); //1
            Renderbuffer depthbuffer = framebuffer.Attach(RenderbufferType.DepthBuffer);      // special

            framebuffer.SetDrawBuffer(GL.GL_COLOR_ATTACHMENT0 + 1);                           // as in 1 in framebuffer.Attach(TextureAttachment.ColorAttachment);//1
            framebuffer.CheckCompleteness();
            framebuffer.Unbind();

            this.BindingTexture = texture;

            return(framebuffer);
        }
Example #8
0
        private static Framebuffer CreateFramebuffer(int width, int height)
        {
            var framebuffer = new Framebuffer(width, height);
            framebuffer.Bind();
            {
                var renderbuffer = new Renderbuffer(width, height, GL.GL_RGBA, RenderbufferType.ColorBuffer);
                framebuffer.Attach(FramebufferTarget.Framebuffer, renderbuffer, 0u);// 0
            }
            {
                var renderbuffer = new Renderbuffer(width, height, GL.GL_DEPTH_COMPONENT24, RenderbufferType.DepthBuffer);
                framebuffer.Attach(FramebufferTarget.Framebuffer, renderbuffer, AttachmentLocation.Depth);// special
            }
            framebuffer.CheckCompleteness();
            framebuffer.Unbind();

            return framebuffer;
        }
Example #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="parameters"></param>
        public override void SetDimensions(int width, int height)
        {
            //  Call the base.
            base.SetDimensions(width, height);

            //  TODO: We should be able to just use the code below - however we
            //  get invalid dimension issues at the moment, so recreate for now.
            ////  Resize the render buffer storage.
            //this.framebuffer.Resize(width, height);

            this.framebuffer.Unbind();
            this.framebuffer.Dispose();
            Framebuffer framebuffer = CreateFramebuffer(width, height, this.Parameters);

            framebuffer.Bind();
            this.framebuffer = framebuffer;
        }
Example #10
0
        /// <summary>
        /// Creates the render context provider. Must also create the OpenGL extensions.
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="bitDepth"></param>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public override bool Create(int width, int height, int bitDepth, object parameter)
        {
            //  Call the base class.
            base.Create(width, height, bitDepth, parameter);

            // Create frame buffer object.
            Framebuffer framebuffer = CreateFramebuffer(width, height);

            framebuffer.Bind();
            this.framebuffer = framebuffer;

            //  Create the DIB section.
            var dibSection = new DIBSection();

            dibSection.Create(this.DeviceContextHandle, width, height, bitDepth);
            this.dibSection = dibSection;

            return(true);
        }
Example #11
0
        /// <summary>
        /// Pick geometry at specified positon.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="pickTriangle"></param>
        /// <param name="pickQuad"></param>
        /// <param name="pickPolygon"></param>
        /// <returns></returns>
        public PickedGeometry Pick(int x, int y, bool pickTriangle, bool pickQuad, bool pickPolygon)
        {
            PickingGeometryTypes geometryTypes = 0;

            if (pickTriangle)
            {
                geometryTypes |= PickingGeometryTypes.Triangle;
            }
            if (pickQuad)
            {
                geometryTypes |= PickingGeometryTypes.Quad;
            }
            if (pickPolygon)
            {
                geometryTypes |= PickingGeometryTypes.Polygon;
            }
            if (geometryTypes == 0)
            {
                return(null);
            }

            PickedGeometry pickedGeometry = null;

            Framebuffer framebuffer = GetPickingFramebuffer();

            framebuffer.Bind();
            {
                const float one = 1.0f;
                GL.Instance.ClearColor(one, one, one, one);
                GL.Instance.Clear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT);

                var arg = new PickingEventArgs(this.Scene, x, y, geometryTypes);
                this.RenderForPicking(this.Scene.RootElement, arg);

                uint stageVertexId = ColorCodedPicking.ReadStageVertexId(x, y);

                pickedGeometry = Pick(stageVertexId, arg, this.Scene.RootElement);
            }
            framebuffer.Unbind();

            return(pickedGeometry);
        }
Example #12
0
        private Framebuffer CreateFramebuffer(int width, int height)
        {
            //Renderbuffer colorBuffer = Renderbuffer.CreateColorbuffer(width, height, GL.GL_RGBA);
            //Renderbuffer depthBuffer = Renderbuffer.CreateDepthbuffer(width, height, DepthComponentType.DepthComponent24);
            var framebuffer = new Framebuffer(width, height);

            framebuffer.Bind();
            //framebuffer.Attach(colorBuffer);//0
            this.BindingTexture = framebuffer.Attach(TextureAttachment.DepthAttachment);//1
            //framebuffer.Attach(depthBuffer);// special
            //framebuffer.SetDrawBuffers(GL.GL_COLOR_ATTACHMENT0 + 1);// as in 1 in framebuffer.Attach(texture);//1
            //framebuffer.SetDrawBuffers(GL.GL_NONE);
            framebuffer.SetDrawBuffer(GL.GL_NONE);
            //framebuffer.SetReadBuffer(GL.GL_NONE);
            this.BindingTexture.Bind();
            framebuffer.CheckCompleteness();
            this.BindingTexture.Unbind();
            framebuffer.Unbind();
            return(framebuffer);
        }
Example #13
0
        private static Framebuffer CreateFramebuffer(int width, int height, ContextGenerationParams parameters)
        {
            var framebuffer = new Framebuffer(width, height);

            framebuffer.Bind();
            {
                var  renderbuffer            = new Renderbuffer(width, height, GL.GL_RGBA);
                uint colorAttachmentLocation = 0;
                framebuffer.Attach(FramebufferTarget.Framebuffer, renderbuffer, colorAttachmentLocation);// 0
            }
            {
                var renderbuffer = new Renderbuffer(width, height, GL.GL_DEPTH_COMPONENT24);
                framebuffer.Attach(FramebufferTarget.Framebuffer, renderbuffer, AttachmentLocation.Depth);// special
            }
            if (parameters.StencilBits > 0)
            {
                var renderbuffer = new Renderbuffer(width, height, GL.GL_STENCIL_INDEX8);
                framebuffer.Attach(FramebufferTarget.Framebuffer, renderbuffer, AttachmentLocation.Stencil);
            }
            framebuffer.CheckCompleteness();
            framebuffer.Unbind();

            return(framebuffer);
        }
Example #14
0
        private static Framebuffer CreateFramebuffer(int width, int height)
        {
            Renderbuffer colorBuffer = Renderbuffer.CreateColorbuffer(width, height, OpenGL.GL_RGBA);
            Renderbuffer depthBuffer = Renderbuffer.CreateDepthbuffer(width, height, DepthComponentType.DepthComponent24);
            var framebuffer = new Framebuffer();
            framebuffer.Bind();
            framebuffer.Attach(colorBuffer);
            framebuffer.Attach(depthBuffer);

            framebuffer.CheckCompleteness();

            return framebuffer;
        }