Пример #1
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();
            }
        }
Пример #2
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();
            }
        }