コード例 #1
0
ファイル: FrameBuffer.cs プロジェクト: alexturpin/Zombles
        /// <summary>
        /// Constructor to create a new FrameBuffer instance.
        /// </summary>
        /// <param name="tex">Texture the frame buffer will write to</param>
        public FrameBuffer(Texture tex, int depthBits = 0)
        {
            Texture = tex;

            // Prepare the target texture for use
            Texture.Bind();

            if (depthBits > 0) {
                _depthBufferID = GL.GenRenderbuffer();

                RenderbufferStorage rbStorage;
                switch (depthBits) {
                    case 16:
                        rbStorage = RenderbufferStorage.DepthComponent16; break;
                    case 24:
                        rbStorage = RenderbufferStorage.DepthComponent24; break;
                    case 32:
                        rbStorage = RenderbufferStorage.DepthComponent32; break;
                    default:
                        throw new ArgumentException("Invalid depth buffer bit count.");
                }

                GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, _depthBufferID);
                GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, rbStorage, tex.Width, tex.Height);
                GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, 0);
            }

            // Assign the texture to the frame buffer
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, FboID);
            GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, tex.TextureTarget, tex.TextureID, 0);
            GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, RenderbufferTarget.Renderbuffer, _depthBufferID);
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);

            Tools.ErrorCheck("fbo_init");
        }