示例#1
0
        public virtual void Process(int width, int height, GLTextuer2D tex, GLTextuer2D output)
        {
            IGL.Primary.Enable((int)EnableCap.Dither);

            Width  = width;
            Height = height;

            CreateBuffersIfNeeded();

            if (renderQuad == null)
            {
                renderQuad = new FullScreenQuad();
            }

            //these must be disabled
            //otherwise image processing will not work properly
            IGL.Primary.Disable((int)EnableCap.DepthTest);
            //IGL.Primary.Disable((int)EnableCap.CullFace);
            IGL.Primary.Disable((int)EnableCap.Blend);
            frameBuff.Bind();
            IGL.Primary.Viewport(0, 0, width, height);
            IGL.Primary.ClearColor(0, 0, 0, 0);
            IGL.Primary.Clear((int)ClearBufferMask.ColorBufferBit);
            IGL.Primary.Clear((int)ClearBufferMask.DepthBufferBit);
        }
示例#2
0
        protected void CreateBuffersIfNeeded()
        {
            if (resizeProcessor == null)
            {
                resizeProcessor = new PreviewProcessor();
            }
            if (renderBuff == null)
            {
                renderBuff = new GLRenderBuffer();
                renderBuff.Bind();
                renderBuff.SetBufferStorageAsDepth(4096, 4096);
                Console.WriteLine("render buff id: " + renderBuff.Id);
                GLRenderBuffer.Unbind();
            }
            if (colorBuff == null)
            {
                //colorbuff part of the framebuffer is always Rgba32f to support all texture formats
                //that could be rendered into it
                colorBuff = new GLTextuer2D(PixelInternalFormat.Rgba32f);
                colorBuff.Bind();
                colorBuff.SetData(new float[0], PixelFormat.Rgba, 4096, 4096);
                colorBuff.SetFilter((int)TextureMinFilter.Linear, (int)TextureMagFilter.Linear);
                Console.WriteLine("color buff id: " + colorBuff.Id);
                GLTextuer2D.Unbind();
            }
            if (frameBuff == null)
            {
                frameBuff = new GLFrameBuffer();
                Console.WriteLine("frame buff id: " + frameBuff.Id);
                frameBuff.Bind();
                frameBuff.AttachColor(colorBuff);
                frameBuff.AttachDepth(renderBuff);
                GL.DrawBuffer(DrawBufferMode.ColorAttachment0);
                GL.ReadBuffer(ReadBufferMode.ColorAttachment0);

                if (!frameBuff.IsValid)
                {
                    var status = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer);
                    Console.WriteLine("Framebuffer not complete!!! with status: " + status);
                    GLFrameBuffer.Unbind();
                    return;
                }

                GLFrameBuffer.Unbind();
            }
        }
示例#3
0
        protected void CreateBuffersIfNeeded()
        {
            if (resizeProcessor == null)
            {
                resizeProcessor = new PreviewProcessor();
            }
            if (renderBuff == null)
            {
                renderBuff = new GLRenderBuffer();
                renderBuff.Bind();
                renderBuff.SetBufferStorageAsDepth(4096, 4096);
                GLRenderBuffer.Unbind();
            }
            if (colorBuff == null)
            {
                //colorbuff part of the framebuffer is always Rgba32f to support all texture formats
                //that could be rendered into it
                colorBuff = new GLTextuer2D(PixelInternalFormat.Rgba32f);
                colorBuff.Bind();
                colorBuff.SetData(IntPtr.Zero, PixelFormat.Rgba, 4096, 4096);
                colorBuff.Nearest();
                colorBuff.Repeat();
                GLTextuer2D.Unbind();
            }
            if (frameBuff == null)
            {
                frameBuff = new GLFrameBuffer();
                frameBuff.Bind();
                frameBuff.AttachColor(colorBuff);
                frameBuff.AttachDepth(renderBuff);
                IGL.Primary.DrawBuffers(new int[] { (int)DrawBufferMode.ColorAttachment0 });
                IGL.Primary.ReadBuffer((int)ReadBufferMode.ColorAttachment0);

                if (!frameBuff.IsValid)
                {
                    var status = IGL.Primary.CheckFramebufferStatus((int)FramebufferTarget.Framebuffer);
                    GLFrameBuffer.Unbind();
                    return;
                }

                GLFrameBuffer.Unbind();
            }
        }
示例#4
0
        public override void Render(GLTextuer2D[] inputs, out GLTextuer2D[] outputs)
        {
            outputs = color;

            if (Meshes == null)
            {
                return;
            }

            frame.Bind();
            IGL.Primary.DrawBuffers(new int[] { (int)DrawBuffersEnum.ColorAttachment0, (int)DrawBuffersEnum.ColorAttachment1 });
            IGL.Primary.Viewport(0, 0, width, height);
            IGL.Primary.ClearColor(0, 0, 0, 0);
            IGL.Primary.Clear((int)ClearBufferMask.ColorBufferBit);
            IGL.Primary.Clear((int)ClearBufferMask.DepthBufferBit);
            for (int i = 0; i < Meshes.Length; ++i)
            {
                Meshes[i].Draw();
            }
            GLFrameBuffer.Unbind();
        }
示例#5
0
        protected void Blit(GLTextuer2D output, int width, int height)
        {
            if (temp == null)
            {
                temp = new GLFrameBuffer();
            }
            temp.Bind();
            temp.BindRead();
            temp.AttachColor(colorBuff, 0);
            IGL.Primary.ReadBuffer((int)ReadBufferMode.ColorAttachment0);
            temp.AttachColor(output, 1);
            IGL.Primary.DrawBuffers(new int[] { (int)DrawBufferMode.ColorAttachment1 });

            if (!temp.IsValid)
            {
                Log.Error("Frame buff is invalid on blit:\r\n" + Environment.StackTrace);
            }

            IGL.Primary.BlitFramebuffer(0, 0, width, height, 0, 0, width, height, (int)ClearBufferMask.ColorBufferBit, (int)BlitFramebufferFilter.Linear);
            GLFrameBuffer.UnbindRead();
            GLFrameBuffer.Unbind();
            frameBuff.Bind();
        }
示例#6
0
        public BasePass(MeshRenderer[] m, int w, int h)
        {
            Meshes = m;

            color = new GLTextuer2D[2];

            width  = w;
            height = h;

            for (int i = 0; i < color.Length; i++)
            {
                color[i] = new GLTextuer2D(PixelInternalFormat.Rgba16f);
                color[i].Bind();
                color[i].SetData(IntPtr.Zero, PixelFormat.Rgba, w, h);
                color[i].Linear();
                color[i].ClampToEdge();
                GLTextuer2D.Unbind();
            }

            depth = new GLRenderBuffer();
            depth.Bind();
            depth.SetBufferStorageAsDepth(w, h);
            GLRenderBuffer.Unbind();

            frame = new GLFrameBuffer();
            frame.Bind();
            frame.AttachColor(color[0], 0);
            frame.AttachColor(color[1], 1);
            frame.AttachDepth(depth);

            if (!frame.IsValid)
            {
                Log.Error("Invalid frame buffer");
            }

            GLFrameBuffer.Unbind();
        }