Пример #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();
            }
        }
Пример #3
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();
        }
Пример #4
0
        public void Update(MeshRenderer[] m, int w, int h)
        {
            Meshes = m;

            width  = w;
            height = h;

            if (color != null)
            {
                for (int i = 0; i < color.Length; ++i)
                {
                    color[i].Bind();
                    color[i].SetData(IntPtr.Zero, PixelFormat.Rgba, w, h);
                    GLTextuer2D.Unbind();
                }
            }

            if (depth != null)
            {
                depth.Bind();
                depth.SetBufferStorageAsDepth(w, h);
                GLRenderBuffer.Unbind();
            }
        }