Пример #1
0
 public void BindFramebuffer(GLFramebufferTarget target, GLFramebufferHandle fb)
 {
     //if (!AppDomain.CurrentDomain.IsDefaultAppDomain())
     //	System.Diagnostics.Debug.WriteLine(AppDomain.CurrentDomain.FriendlyName + " bound " + fb);
     _currentFramebufferBinding = fb;
     GL.BindFramebuffer((FramebufferTarget)target, (int)fb);
 }
Пример #2
0
        public void Flush(NSOpenGLContext ctx)
        {
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
            GL.Flush();             // We flush to be sure the framebuffer texture has the data we want

            SurfaceRendered.OnNext(_backbuffer.Value.Surface);

            Swap();
        }
Пример #3
0
        private void CreateFramebuffer()
        {
            this.glControl.MakeCurrent();

            if (this.framebufferId > 0)
            {
                GL.DeleteFramebuffer(this.framebufferId);
            }

            if (this.depthbufferId > 0)
            {
                GL.DeleteRenderbuffer(this.depthbufferId);
            }

            if (this.colorbufferId > 0)
            {
                GL.DeleteRenderbuffer(this.colorbufferId);
            }

            this.framebufferId = GL.GenFramebuffer();
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, this.framebufferId);

            this.colorbufferId = GL.GenRenderbuffer();
            GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, this.colorbufferId);
            GL.RenderbufferStorage(
                RenderbufferTarget.Renderbuffer,
                RenderbufferStorage.Rgba8,
                this.size.Width,
                this.size.Height);
            GL.FramebufferRenderbuffer(
                FramebufferTarget.Framebuffer,
                FramebufferAttachment.ColorAttachment0,
                RenderbufferTarget.Renderbuffer,
                this.colorbufferId);

            this.depthbufferId = GL.GenRenderbuffer();
            GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, this.depthbufferId);
            GL.RenderbufferStorage(
                RenderbufferTarget.Renderbuffer,
                RenderbufferStorage.DepthComponent24,
                this.size.Width,
                this.size.Height);
            GL.FramebufferRenderbuffer(
                FramebufferTarget.Framebuffer,
                FramebufferAttachment.DepthAttachment,
                RenderbufferTarget.Renderbuffer,
                this.depthbufferId);

            FramebufferErrorCode error = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer);

            if (error != FramebufferErrorCode.FramebufferComplete)
            {
                throw new Exception();
            }

            this.loaded = true;
        }
Пример #4
0
 private void _ClearTexture(COGLTexture texture)
 {
     if (texture.DataSize.Equals(texture.Size))
     {
         return;
     }
     GL.BindFramebuffer(OpenTK.Graphics.OpenGL.FramebufferTarget.Framebuffer, _FBO);
     GL.FramebufferTexture2D(OpenTK.Graphics.OpenGL.FramebufferTarget.Framebuffer, OpenTK.Graphics.OpenGL.FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D,
                             texture.Name, 0);
     GL.ClearColor(Color.FromArgb(0));
     GL.Clear(ClearBufferMask.ColorBufferBit);
     GL.ClearColor(Color.Black);
     GL.BindFramebuffer(OpenTK.Graphics.OpenGL.FramebufferTarget.Framebuffer, 0);
 }
Пример #5
0
        internal void Prepare(Size framebuffersize)
        {
            if (GraphicsContext.CurrentContext != this.glControl.Context)
            {
                this.glControl.MakeCurrent();
            }

            if (framebuffersize != this.size || this.loaded == false)
            {
                this.size = framebuffersize;
                this.CreateFramebuffer();

                GL.Viewport(0, 0, framebuffersize.Width, framebuffersize.Height);
                this.scene.Camera.ResizeViewport(framebuffersize.Width, framebuffersize.Height);
                Matrix4 projMatrix = scene.Camera.ProjMatrix;
                GL.MatrixMode(MatrixMode.Projection);
                GL.LoadMatrix(ref projMatrix);
            }

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, this.framebufferId);
        }
Пример #6
0
        public static FramebufferInfo CreateFramebuffer(this IOSurface surface)
        {
            var size = surface.Size.Max(1, 1);

            var handles = new int[1];

            GL.GenFramebuffers(1, handles);
            var handle = new FramebufferHandle(handles[0]);

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, handle);

            var depthbuffer = CreateDepthBuffer(size);

            GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, RenderbufferTarget.Renderbuffer, depthbuffer);

            var colorbuffer = IOSurfaceTexture.Create(size, surface);

            GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.TextureRectangle, colorbuffer, 0);

            CheckStatus();

            return(new FramebufferInfo(handle, depthbuffer, Optional.None(), colorbuffer));
        }
Пример #7
0
 public void BindFramebuffer(GLFramebufferTarget target, GLFramebufferHandle fb)
 {
     _currentFramebufferBinding = fb;
     MacGL.BindFramebuffer((FramebufferTarget)target, (int)fb);
 }