コード例 #1
0
ファイル: VFrameBuffer.cs プロジェクト: VividMaster/Vivid3D2
        public VFrameBuffer(int w, int h)
        {
            IW  = w;
            IH  = h;
            FBO = GL.GenFramebuffer();
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, FBO);
            BB  = new VTex2D(w, h, false);
            DB  = new VTexDepth(w, h);
            DRB = GL.GenRenderbuffer();
            GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, DRB);
            GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, RenderbufferStorage.DepthComponent, w, h);
            GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, RenderbufferTarget.Renderbuffer, DRB);
            GL.FramebufferTexture(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, BB.ID, 0);
            DrawBuffersEnum db = DrawBuffersEnum.ColorAttachment0;

            GL.DrawBuffers(1, ref db);
            if (GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer) != FramebufferErrorCode.FramebufferComplete)
            {
                Console.WriteLine("Framebuffer failure.");
                while (true)
                {
                }
            }
            Console.WriteLine("Framebuffer success.");
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
            GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, 0);
        }
コード例 #2
0
        public void Clear()
        {
            int[]   viewport  = new int[4];
            float[] clearCols = new float[4];

            GL.GetInteger(GetPName.Viewport, viewport);
            GL.GetFloat(GetPName.ColorClearValue, clearCols);

            GL.ClearColor(0, 0, 0, 0);
            GL.Viewport(0, 0, width, height);

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, fbo);

            drawBuffs = new DrawBuffersEnum[] { DrawBuffersEnum.ColorAttachment0 };
            GL.DrawBuffers(drawBuffs.Length, drawBuffs);
            GL.Clear(ClearBufferMask.ColorBufferBit);

            drawBuffs = new DrawBuffersEnum[] { DrawBuffersEnum.ColorAttachment1 };
            GL.DrawBuffers(drawBuffs.Length, drawBuffs);
            GL.Clear(ClearBufferMask.ColorBufferBit);

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);

            GL.ClearColor(clearCols[0], clearCols[1], clearCols[2], clearCols[3]);
            GL.Viewport(viewport [0], viewport [1], viewport [2], viewport [3]);
        }
コード例 #3
0
        public static void Init(int size)
        {
            DrawBuffersEnum[] buffers = new DrawBuffersEnum[6]
            {
                DrawBuffersEnum.ColorAttachment0, DrawBuffersEnum.ColorAttachment1,
                DrawBuffersEnum.ColorAttachment2, DrawBuffersEnum.ColorAttachment3,
                DrawBuffersEnum.ColorAttachment4, DrawBuffersEnum.ColorAttachment5,
            };

            FilterLevel0 = new Framebuffer(FramebufferTarget.Framebuffer);
            FilterLevel1 = new Framebuffer(FramebufferTarget.Framebuffer);
            FilterLevel0.SetDrawBuffers(buffers);
            FilterLevel1.SetDrawBuffers(buffers);

            var normalsDDS = new DDS(new System.IO.MemoryStream(Properties.Resources.normals));

            NormalsTexture = GLTexture2D.FromGeneric(normalsDDS, new ImageParameters());

            NormalsTexture.Bind();
            NormalsTexture.WrapR     = TextureWrapMode.ClampToEdge;
            NormalsTexture.WrapT     = TextureWrapMode.ClampToEdge;
            NormalsTexture.WrapS     = TextureWrapMode.ClampToEdge;
            NormalsTexture.MinFilter = TextureMinFilter.Nearest;
            NormalsTexture.MagFilter = TextureMagFilter.Nearest;
            NormalsTexture.UpdateParameters();
            NormalsTexture.Unbind();
        }
コード例 #4
0
        public void GenerateFramebuffer(GameWindow window)
        {
            //Generate framebuffer
            _framebuffer = GL.GenFramebuffer();
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, _framebuffer);

            // create a RGBA color texture
            GL.GenTextures(1, out _textureColorBuffer);
            GL.BindTexture(TextureTarget.Texture2D, _textureColorBuffer);
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba,
                          window.Width, window.Height / 2,
                          0, (PixelFormat)PixelInternalFormat.Rgba, PixelType.UnsignedByte,
                          IntPtr.Zero);

            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMinFilter.Nearest);
            GL.BindTexture(TextureTarget.Texture2D, 0);


            ////Create color attachment texture
            GL.FramebufferTexture(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, _textureColorBuffer, 0);

            DrawBuffersEnum[] bufs = new DrawBuffersEnum[1] {
                (DrawBuffersEnum)FramebufferAttachment.ColorAttachment0
            };
            GL.DrawBuffers(bufs.Length, bufs);

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
        }
コード例 #5
0
ファイル: Drawing.cs プロジェクト: qoh/TISFAT-Zero
        private static void InitShadows()
        {
            GL.GenFramebuffers(1, out ShadowsFBO);

            GL.GenTextures(1, out ShadowsTexture);
            GL.BindTexture(TextureTarget.Texture2D, ShadowsTexture);

            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);

            int size = Math.Max(NextPowerOf2(Program.ActiveProject.Width), NextPowerOf2(Program.ActiveProject.Height));

            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, size, size, 0, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);

            GL.BindTexture(TextureTarget.Texture2D, 0);

            GL.GenFramebuffers(1, out ShadowsFBO);

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, ShadowsFBO);
            GL.FramebufferTexture(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, ShadowsTexture, 0);

            DrawBuffersEnum[] bufferEnum = new DrawBuffersEnum[1] {
                (DrawBuffersEnum)FramebufferAttachment.ColorAttachment0
            };
            GL.DrawBuffers(bufferEnum.Length, bufferEnum);

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);

            ShadowsInit = true;
        }
コード例 #6
0
ファイル: BrushShader.cs プロジェクト: jpbruyere/Ottd3D
        public void Clear()
        {
            int[] viewport = new int[4];
            float[] clearCols = new float[4];

            GL.GetInteger (GetPName.Viewport, viewport);
            GL.GetFloat (GetPName.ColorClearValue, clearCols);

            GL.ClearColor (0, 0, 0, 0);
            GL.Viewport(0, 0, width, height);

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, fbo);

            drawBuffs = new DrawBuffersEnum[] {	DrawBuffersEnum.ColorAttachment0 };
            GL.DrawBuffers(drawBuffs.Length, drawBuffs);
            GL.Clear (ClearBufferMask.ColorBufferBit);

            drawBuffs = new DrawBuffersEnum[] {	DrawBuffersEnum.ColorAttachment1 };
            GL.DrawBuffers(drawBuffs.Length, drawBuffs);
            GL.Clear (ClearBufferMask.ColorBufferBit);

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);

            GL.ClearColor(clearCols[0], clearCols[1], clearCols[2], clearCols[3]);
            GL.Viewport (viewport [0], viewport [1], viewport [2], viewport [3]);
        }
コード例 #7
0
        /// <summary>
        /// Binds the framebuffer and all of the renderbuffers.
        /// Clears the buffer bits and sets viewport size.
        /// Perform all rendering after this call.
        /// </summary>
        public void Enable()
        {
            Gl.BindFramebuffer(FramebufferTarget.Framebuffer, BufferID);
            if (Attachments.Length == 1)
            {
                Gl.BindTexture(TextureTarget.Texture2D, TextureID[0]);
                Gl.FramebufferTexture(FramebufferTarget.Framebuffer, Attachments[0], TextureID[0], 0);
            }
            else
            {
                DrawBuffersEnum[] buffers = new DrawBuffersEnum[Attachments.Length];

                for (int i = 0; i < Attachments.Length; i++)
                {
                    Gl.BindTexture(TextureTarget.Texture2D, TextureID[i]);
                    Gl.FramebufferTexture(FramebufferTarget.Framebuffer, Attachments[i], TextureID[i], 0);
                    buffers[i] = (DrawBuffersEnum)Attachments[i];
                }
                if (Attachments.Length > 1)
                {
                    Gl.DrawBuffers(Attachments.Length, buffers);
                }
            }

            Gl.Viewport(0, 0, Size.Width, Size.Height);

            if (Attachments.Length == 1 && Attachments[0] == FramebufferAttachment.DepthAttachment)
            {
                Gl.Clear(ClearBufferMask.DepthBufferBit);
            }
            else
            {
                Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            }
        }
コード例 #8
0
        public FrameBuffer(int w, int h)
        {
            GL.GenFramebuffers(1, out mFrameBufferId);
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, mFrameBufferId);

            Texture = new Texture(w, h);

            GL.GenRenderbuffers(1, out mDepthId);
            GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, mDepthId);
            GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, RenderbufferStorage.DepthComponent, w, h);

            GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, RenderbufferTarget.Renderbuffer, mDepthId);
            GL.FramebufferTexture(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, Texture.Id, 0);

            // Set the list of draw buffers.
            DrawBuffersEnum DrawBuffers = DrawBuffersEnum.ColorAttachment0;

            GL.DrawBuffers(1, ref DrawBuffers);            // "1" is the size of DrawBuffe

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

            if (result != FramebufferErrorCode.FramebufferComplete)
            {
                Logger.Instance.Append("Framebuffer failed status : " + result.ToString());
            }
        }
コード例 #9
0
ファイル: FrameBuffer.cs プロジェクト: vijirams/KailashEngine
        // Bind Draw Attachements Only
        public void bindAttachements(DrawBuffersEnum draw_attachment)
        {
            DrawBuffersEnum[] temp_attchements = new DrawBuffersEnum[] { draw_attachment };

            int buffer_count = temp_attchements.Length;

            GL.DrawBuffers(buffer_count, temp_attchements);
        }
コード例 #10
0
        private void blur_Gauss(
            fx_Quad quad,
            int blur_amount,
            Vector2 horizontal_mod, Vector2 vertical_mod,
            Texture texture_to_blur, FrameBuffer texture_frame_buffer, DrawBuffersEnum attachement,
            float destination_scale = 1)
        {
            _pBlur_Gauss.bind();


            GL.Uniform1(_pBlur_Gauss.getUniform("blur_amount"), blur_amount);


            Vector2 texture_to_blur_size = new Vector2(texture_to_blur.width, texture_to_blur.height) * destination_scale;

            Vector2 horizontal_texture_size = new Vector2(1.0f / texture_to_blur_size.X, 1.0f / texture_to_blur_size.Y);
            Vector2 vertical_texture_size   = new Vector2(1.0f / _tSpecial.width, 1.0f / _tSpecial.height);


            //------------------------------------------------------
            // Horizontal
            //------------------------------------------------------
            // Bind special texture and clear it
            clearAndBindSpecialFrameBuffer();
            GL.Viewport(0, 0, (int)texture_to_blur_size.X, (int)texture_to_blur_size.Y);

            GL.Uniform2(_pBlur_Gauss.getUniform("texture_size"), horizontal_mod * horizontal_texture_size);

            // Source
            texture_to_blur.bind(_pBlur_Gauss.getSamplerUniform(0), 0);

            quad.render();


            //------------------------------------------------------
            // Vertical
            //------------------------------------------------------

            // If client supplies framebuffer for desintation, use that. Otherwise attach destination to special framebuffer
            if (texture_frame_buffer.id != _fSpecial.id)
            {
                texture_frame_buffer.bind(attachement);
            }
            else
            {
                bindExternalTexture(texture_to_blur);
            }
            GL.Viewport(0, 0, (int)(_tSpecial.width / destination_scale), (int)(_tSpecial.height / destination_scale));



            GL.Uniform2(_pBlur_Gauss.getUniform("texture_size"), vertical_mod * vertical_texture_size);

            // Source
            _tSpecial.bind(_pBlur_Gauss.getSamplerUniform(0), 0);

            quad.render();
        }
コード例 #11
0
ファイル: FrameBuffer.cs プロジェクト: splitandthechro/nginz
 public Framebuffer AttachTexture(FboAttachment attachment, DrawBuffersEnum mode, PixelInternalFormat internalFormat, PixelFormat format, PixelType type, InterpolationMode interpolation)
 {
     this.Attachments.Add (mode);
     this.BufferTextures[attachment] = new Texture2D (TextureTarget.Texture2D, internalFormat, format, type, interpolation, false, this.Width, this.Height);
     this.Bind ();
     this.BufferTextures[attachment].Bind ();
     GL.FramebufferTexture (this.Target, (FramebufferAttachment) mode, this.BufferTextures[attachment].TextureId, 0);
     this.Unbind ();
     return this;
 }
コード例 #12
0
 public Framebuffer AttachTexture(FboAttachment attachment, DrawBuffersEnum mode, PixelInternalFormat internalFormat, PixelFormat format, PixelType type, InterpolationMode interpolation)
 {
     this.Attachments.Add(mode);
     this.BufferTextures[attachment] = new Texture2D(TextureTarget.Texture2D, internalFormat, format, type, interpolation, false, this.Width, this.Height);
     this.Bind();
     this.BufferTextures[attachment].Bind();
     GL.FramebufferTexture(this.Target, (FramebufferAttachment)mode, this.BufferTextures[attachment].TextureId, 0);
     this.Unbind();
     return(this);
 }
コード例 #13
0
        public static void Init(int size)
        {
            Filter = new Framebuffer(FramebufferTarget.Framebuffer, size, size, PixelInternalFormat.R11fG11fB10f);
            DrawBuffersEnum[] drawBuffers = new DrawBuffersEnum[size];
            for (int i = 0; i < size; i++)
            {
                drawBuffers[i] = DrawBuffersEnum.ColorAttachment0 + i;
            }

            Filter.SetDrawBuffers(drawBuffers);
        }
コード例 #14
0
        /// <inheritdoc />
        public override void Compile()
        {
            if (_id == 0)
            {
                _window = ScreenWindow;
            }
            if (_window != null)
            {
                Size = new Vector2(_window.Width * _windowScale, _window.Height * _windowScale);
            }

            base.Compile();
            _id = GL.GenFramebuffer();
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, _id);

            var enums = new DrawBuffersEnum[ColorAttachments.Count];
            var c     = 0;

            foreach (var pair in ColorAttachments)
            {
                pair.Value.Generate(this);

                enums[c++] = pair.Value.DrawBuffersEnum;
            }

            GL.DrawBuffers(enums.Length, enums);
            foreach (var pair in ColorAttachments)
            {
                GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, pair.Value.FramebufferAttachment, pair.Value.Target, pair.Value.ID,
                                        0);
            }
            FramebufferErrorCode err;

            err = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer);
            if (err != FramebufferErrorCode.FramebufferComplete)
            {
                throw new Exception("Failed loading framebuffer.\nProblem: " + err);
            }

            foreach (RenderbufferAttachment attachment in RenderbufferAttachments)
            {
                attachment.Generate(this);
                GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, attachment.FramebufferAttachment, RenderbufferTarget.Renderbuffer, attachment.ID);
            }

            err = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer);
            if (err != FramebufferErrorCode.FramebufferComplete)
            {
                throw new Exception("Failed loading framebuffer.\nProblem: " + err);
            }

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
            GL.BindTexture(TextureTarget.Texture2D, 0);
        }
コード例 #15
0
ファイル: RenderTarget.cs プロジェクト: beardgame/graphics
            public void SetColorAttachments(params Texture[] textures)
            {
                var attachments = new DrawBuffersEnum[textures.Length];

                foreach (var index in Enumerable.Range(0, textures.Length))
                {
                    Attach(FramebufferAttachment.ColorAttachment0 + index, textures[index]);
                    attachments[index] = DrawBuffersEnum.ColorAttachment0 + index;
                }
                GL.DrawBuffers(attachments.Length, attachments);
            }
コード例 #16
0
        private void SetDrawBuffersImpl(int colorsCount)
        {
            DrawBuffersEnum[] drawBuffers = new DrawBuffersEnum[colorsCount];

            for (int index = 0; index < colorsCount; index++)
            {
                drawBuffers[index] = DrawBuffersEnum.ColorAttachment0 + index;
            }

            GL.DrawBuffers(colorsCount, drawBuffers);
        }
コード例 #17
0
        public void blur_Streak(
            fx_Quad quad,
            int blur_amount, float streak_angle,
            Texture texture_to_blur, FrameBuffer texture_frame_buffer, DrawBuffersEnum attachement,
            float destination_scale = 1)
        {
            _pBlur_Streak.bind();

            GL.Uniform1(_pBlur_Streak.getUniform("blur_amount"), blur_amount);
            Vector2 rotation_vector = EngineHelper.createRotationVector(streak_angle);


            Vector2 texture_to_blur_size     = new Vector2(texture_to_blur.width, texture_to_blur.height) * destination_scale;
            Vector2 destination_texture_size = new Vector2(1.0f / texture_to_blur_size.X, 1.0f / texture_to_blur_size.Y);
            Vector2 source_texture_size      = new Vector2(1.0f / _tSpecial.width, 1.0f / _tSpecial.height);

            //------------------------------------------------------
            // Iteration 1
            //------------------------------------------------------
            // Bind special texture and clear it
            clearAndBindSpecialFrameBuffer();
            GL.Viewport(0, 0, (int)texture_to_blur_size.X, (int)texture_to_blur_size.Y);


            GL.Uniform2(_pBlur_Streak.getUniform("size_and_direction"), rotation_vector * destination_texture_size);
            GL.Uniform1(_pBlur_Streak.getUniform("iteration"), 0);
            texture_to_blur.bind(_pBlur_Streak.getSamplerUniform(0), 0);

            quad.render();


            //------------------------------------------------------
            // Iteration 2
            //------------------------------------------------------
            // Bind special texture and clear it
            if (texture_frame_buffer.id != _fSpecial.id)
            {
                texture_frame_buffer.bind(attachement);
            }
            else
            {
                bindExternalTexture(texture_to_blur);
            }
            GL.Viewport(0, 0, (int)(_tSpecial.width / destination_scale), (int)(_tSpecial.height / destination_scale));


            GL.Uniform2(_pBlur_Streak.getUniform("size_and_direction"), rotation_vector * source_texture_size);
            GL.Uniform1(_pBlur_Streak.getUniform("iteration"), 1);
            _tSpecial.bind(_pBlur_Streak.getSamplerUniform(0), 0);


            quad.render();
        }
コード例 #18
0
        static void Init(int size)
        {
            DrawBuffersEnum[] buffers = new DrawBuffersEnum[6]
            {
                DrawBuffersEnum.ColorAttachment0, DrawBuffersEnum.ColorAttachment1,
                DrawBuffersEnum.ColorAttachment2, DrawBuffersEnum.ColorAttachment3,
                DrawBuffersEnum.ColorAttachment4, DrawBuffersEnum.ColorAttachment5,
            };

            frameBuffer = new Framebuffer(FramebufferTarget.Framebuffer, size, size, PixelInternalFormat.R11fG11fB10f, 0, false);
            frameBuffer.SetDrawBuffers(buffers);
        }
コード例 #19
0
        internal void Clean()
        {
            if (_colorAttachments.Dirty)
            {
                ColorAttachmentGL3x[] colorAttachments = _colorAttachments.Attachments;

                DrawBuffersEnum[] drawBuffers = new DrawBuffersEnum[colorAttachments.Length];

                for (int i = 0; i < colorAttachments.Length; ++i)
                {
                    if (colorAttachments[i].Dirty)
                    {
                        Attach(FramebufferAttachment.ColorAttachment0 + i, colorAttachments[i].Texture);
                        colorAttachments[i].Dirty = false;
                    }

                    if (colorAttachments[i].Texture != null)
                    {
                        drawBuffers[i] = DrawBuffersEnum.ColorAttachment0 + i;
                    }
                }
                GL.DrawBuffers(drawBuffers.Length, drawBuffers);

                _colorAttachments.Dirty = false;
            }

            if (_dirtyFlags != DirtyFlags.None)
            {
                if ((_dirtyFlags & DirtyFlags.DepthAttachment) == DirtyFlags.DepthAttachment)
                {
                    Attach(FramebufferAttachment.DepthAttachment, _depthAttachment);
                }

                //
                // The depth-stencil attachment overrides the depth attachment:
                //
                //    "Attaching a level of a texture to GL_DEPTH_STENCIL_ATTACHMENT
                //     is equivalent to attaching that level to both the
                //     GL_DEPTH_ATTACHMENT and the GL_STENCIL_ATTACHMENT attachment
                //     points simultaneously."
                //
                // We do not expose just a stencil attachment because TextureFormat
                // does not contain a stencil only format.
                //
                if ((_dirtyFlags & DirtyFlags.DepthStencilAttachment) == DirtyFlags.DepthStencilAttachment)
                {
                    Attach(FramebufferAttachment.DepthStencilAttachment, _depthStencilAttachment);
                }

                _dirtyFlags = DirtyFlags.None;
            }
        }
コード例 #20
0
        internal void Clean()
        {
            if (_colorAttachments.Dirty)
            {
                ColorAttachmentGL3x[] colorAttachments = _colorAttachments.Attachments;
                
                DrawBuffersEnum[] drawBuffers = new DrawBuffersEnum[colorAttachments.Length];

                for (int i = 0; i < colorAttachments.Length; ++i)
                {
                    if (colorAttachments[i].Dirty)
                    {
                        Attach(FramebufferAttachment.ColorAttachment0 + i, colorAttachments[i].Texture);
                        colorAttachments[i].Dirty = false;
                    }

                    if (colorAttachments[i].Texture != null)
                    {
                        drawBuffers[i] = DrawBuffersEnum.ColorAttachment0 + i;
                    }
                }
                GL.DrawBuffers(drawBuffers.Length, drawBuffers);

                _colorAttachments.Dirty = false;
            }

            if (_dirtyFlags != DirtyFlags.None)
            {
                if ((_dirtyFlags & DirtyFlags.DepthAttachment) == DirtyFlags.DepthAttachment)
                {
                    Attach(FramebufferAttachment.DepthAttachment, _depthAttachment);
                }

                //
                // The depth-stencil attachment overrides the depth attachment:
                //
                //    "Attaching a level of a texture to GL_DEPTH_STENCIL_ATTACHMENT 
                //     is equivalent to attaching that level to both the 
                //     GL_DEPTH_ATTACHMENT and the GL_STENCIL_ATTACHMENT attachment 
                //     points simultaneously."
                //
                // We do not expose just a stencil attachment because TextureFormat
                // does not contain a stencil only format.
                //
                if ((_dirtyFlags & DirtyFlags.DepthStencilAttachment) == DirtyFlags.DepthStencilAttachment)
                {
                    Attach(FramebufferAttachment.DepthStencilAttachment, _depthStencilAttachment);
                }

                _dirtyFlags = DirtyFlags.None;
            }
        }
コード例 #21
0
ファイル: GBuffer.cs プロジェクト: whrlpl/engine
        public GBuffer()
        {
            GL.GenFramebuffers(1, out gbo);
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, gbo);


            posBuf    = BindTexture(PixelInternalFormat.Rgb16f, PixelFormat.Rgb, PixelType.Float, FramebufferAttachment.ColorAttachment0);
            normalBuf = BindTexture(PixelInternalFormat.Rgb16f, PixelFormat.Rgb, PixelType.Float, FramebufferAttachment.ColorAttachment1);
            diffBuf   = BindTexture(PixelInternalFormat.Rgba, PixelFormat.Rgba, PixelType.UnsignedByte, FramebufferAttachment.ColorAttachment2);
            DrawBuffersEnum attachments = DrawBuffersEnum.ColorAttachment0 | DrawBuffersEnum.ColorAttachment1 | DrawBuffersEnum.ColorAttachment3;

            GL.DrawBuffers(3, ref attachments);
        }
コード例 #22
0
 public void blur_Gauss(
     fx_Quad quad,
     int blur_amount,
     Texture texture_to_blur, FrameBuffer texture_frame_buffer, DrawBuffersEnum attachement,
     float destination_scale = 1)
 {
     blur_Gauss(
         quad,
         blur_amount,
         new Vector2(1.0f, 0.0f), new Vector2(0.0f, 1.0f),
         texture_to_blur, texture_frame_buffer, attachement,
         destination_scale);
 }
コード例 #23
0
ファイル: GBuffer.cs プロジェクト: mengdada/SharpOpenGL
        public void PrepareToDraw()
        {
            GL.Viewport(0, 0, BufferWidth, BufferHeight);

            var attachments = new DrawBuffersEnum[]
            {
                DrawBuffersEnum.ColorAttachment0,
                DrawBuffersEnum.ColorAttachment1,
                DrawBuffersEnum.ColorAttachment2,
                DrawBuffersEnum.ColorAttachment3,
            };

            GL.DrawBuffers(4, attachments);
        }
コード例 #24
0
        public void blur_Gauss(
            fx_Quad quad,
            int blur_amount, float blur_angle,
            Texture texture_to_blur, FrameBuffer texture_frame_buffer, DrawBuffersEnum attachement,
            float destination_scale = 1)
        {
            Vector2 angle_mod = EngineHelper.createRotationVector(blur_angle);

            blur_Gauss(
                quad,
                blur_amount,
                angle_mod, angle_mod,
                texture_to_blur, texture_frame_buffer, attachement,
                destination_scale);
        }
コード例 #25
0
        public void PointLightPass(Matrix4x4 cameraMatrix, Vector3 cameraPosition, Vector3 cameraDirection)
        {
            pointLightFBO.Activate();
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            renderState.Set(new DepthTest(false));
            renderState.Set(new FaceCullingModeState(FaceCullingMode.FRONT_SIDE));
            renderState.Set(BlendStates.Additive);
            pointLightShader.Activate();

            int position = GL.GetUniformLocation(pointLightShader.ProgramID, "positionSampler");
            int albedo   = GL.GetUniformLocation(pointLightShader.ProgramID, "albedoSampler");
            int normal   = GL.GetUniformLocation(pointLightShader.ProgramID, "normalSampler");

            GL.Uniform1(position, 1);
            GL.Uniform1(albedo, 2);
            GL.Uniform1(normal, 3);

            GL.ActiveTexture(TextureUnit.Texture1);
            GL.BindTexture(TextureTarget.Texture2D, mainFBO.Textures[0].ID);
            GL.ActiveTexture(TextureUnit.Texture2);
            GL.BindTexture(TextureTarget.Texture2D, mainFBO.Textures[1].ID);
            GL.ActiveTexture(TextureUnit.Texture3);
            GL.BindTexture(TextureTarget.Texture2D, mainFBO.Textures[2].ID);


            pointLightShader.Uniform("camera", cameraMatrix);
            pointLightShader.Uniform("cameraPosition", cameraPosition);
            pointLightShader.Uniform("camDir", cameraDirection);
            GL.ActiveTexture(TextureUnit.Texture0);
            pointLightFBO.Textures[0].Activate();

            DrawBuffersEnum[] drawBuffers = new DrawBuffersEnum[1];

            drawBuffers[0] = DrawBuffersEnum.ColorAttachment0;
            GL.DrawBuffers(1, drawBuffers);

            pointLightSphere.Draw(pointLightAmount);

            GL.ActiveTexture(TextureUnit.Texture0);
            pointLightFBO.Textures[0].Deactivate();

            pointLightShader.Deactivate();
            renderState.Set(BlendStates.Opaque);
            renderState.Set(new FaceCullingModeState(FaceCullingMode.NONE));
            renderState.Set(new DepthTest(false));
            pointLightFBO.Deactivate();
        }
コード例 #26
0
        /// <summary>
        /// Binds the framebuffer and all of the renderbuffers.
        /// Clears the buffer bits and sets viewport size.
        /// Perform all rendering after this call.
        /// </summary>
        /// <param name="clear">True to clear both the color and depth buffer bits of the FBO before enabling.</param>
        public void Enable(bool clear = true)
        {
            TextureTarget textureTarget = Multisampled ? TextureTarget.Texture2DMultisample : TextureTarget.Texture2D;

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, BufferID);

            if (Attachments.Length == 1)
            {
                GL.BindTexture(textureTarget, TextureID[0]);
                GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, Attachments[0], textureTarget, TextureID[0], 0);
            }
            else
            {
                DrawBuffersEnum[] buffers = new DrawBuffersEnum[Attachments.Length];

                for (int i = 0; i < Attachments.Length; i++)
                {
                    GL.BindTexture(textureTarget, TextureID[i]);
                    GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, Attachments[i], textureTarget, TextureID[i], 0);
                    buffers[i] = (DrawBuffersEnum)Attachments[i];
                }

                GL.BindTexture(textureTarget, DepthID);
                GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, textureTarget, DepthID, 0);

                if (Attachments.Length > 1)
                {
                    GL.DrawBuffers(Attachments.Length, buffers);
                }
            }

            GL.Viewport(0, 0, Size.Width, Size.Height);

            // configurably clear the buffer and color bits
            if (clear)
            {
                if (Attachments.Length == 1 && Attachments[0] == FramebufferAttachment.DepthAttachment)
                {
                    Renderer.ClearScreen(ClearBufferMask.DepthBufferBit);
                }
                else
                {
                    Renderer.ClearScreen(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit);
                }
            }
        }
コード例 #27
0
        public void AttachColorBuffer(
            PixelInternalFormat internalFormat = PixelInternalFormat.Rgba,
            PixelFormat format         = PixelFormat.Rgba,
            PixelType type             = PixelType.UnsignedByte,
            TextureMinFilter minFilter = TextureMinFilter.Linear,
            TextureMagFilter magFilter = TextureMagFilter.Linear,
            TextureWrapMode wrapMode   = TextureWrapMode.ClampToBorder)
        {
            //gen colorbuffer as texture
            Texture texture = new Texture2d();

            Textures.Add(texture);

            int txtId = texture.Id;

            GL.BindTexture(TextureTarget.Texture2D, txtId);
            GL.TexImage2D(TextureTarget.Texture2D, 0, internalFormat, Size.Width, Size.Height, 0, format, type, IntPtr.Zero);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)minFilter);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)magFilter);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)wrapMode);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)wrapMode);

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, ID);
            GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0 + Textures.Count - 1, TextureTarget.Texture2D, txtId, 0);

            if (Textures.Count > 1)
            {
                DrawBuffersEnum[] e = new DrawBuffersEnum[Textures.Count];
                for (int i = 0; i < Textures.Count; i++)
                {
                    e[i] = DrawBuffersEnum.ColorAttachment0 + i;
                }

                GL.DrawBuffers(Textures.Count, e);
            }

            var status = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer);

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

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
            GL.BindTexture(TextureTarget.Texture2D, 0);
        }
コード例 #28
0
        /// <summary>
        /// Sets the render targets.
        /// </summary>
        /// <param name="depthBuffer">Depth buffer for this frame buffer</param>
        /// <param name="textureList">Array of textures that should be used as a render target.</param>
        public void SetTextures(RenderBuffer depthBuffer, params Texture2D[] textureList)
        {
            this.depthBuffer = depthBuffer;
            this.textures    = textureList;
            OpenGL.Invoke(() =>
            {
                // Setup depth buffer
                GL.BindFramebuffer(FramebufferTarget.Framebuffer, this.id);
                int depthBufferID = 0;
                if (this.depthBuffer != null)
                {
                    depthBufferID = this.depthBuffer.Id;
                }
                GL.FramebufferRenderbuffer(
                    FramebufferTarget.Framebuffer,
                    FramebufferAttachment.DepthAttachment,
                    RenderbufferTarget.Renderbuffer,
                    depthBufferID);

                if (this.textures != null)
                {
                    DrawBuffersEnum[] drawBuffers = new DrawBuffersEnum[this.textures.Length];
                    for (int i = 0; i < this.textures.Length; i++)
                    {
                        GL.FramebufferTexture(
                            FramebufferTarget.Framebuffer,
                            FramebufferAttachment.ColorAttachment0 + i,
                            this.textures[i].Id, 0);
                        drawBuffers[i] = DrawBuffersEnum.ColorAttachment0 + i;
                    }

                    GL.DrawBuffers(drawBuffers.Length, drawBuffers);
                }
                else
                {
                    GL.DrawBuffers(0, new DrawBuffersEnum[0]);
                }

                FramebufferErrorCode error;
                if ((error = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer)) != FramebufferErrorCode.FramebufferComplete)
                {
                    throw new InvalidOperationException("Failed to bind FrameBuffer: " + error);
                }
            });
        }
コード例 #29
0
        public override void Update()
        {
            evenCycle = !evenCycle;

            GL.ActiveTexture(TextureUnit.Texture0);
            if (evenCycle)
            {
                drawBuffs = new DrawBuffersEnum[] { DrawBuffersEnum.ColorAttachment1 };
                GL.BindTexture(TextureTarget.Texture2D, tex);
            }
            else
            {
                drawBuffs = new DrawBuffersEnum[] { DrawBuffersEnum.ColorAttachment0 };
                GL.BindTexture(TextureTarget.Texture2D, evenTex);
            }

            base.Update();
        }
コード例 #30
0
ファイル: OGLFrameBuffer.cs プロジェクト: pinguicodes/Ryujinx
        public void SetMap(int[] Map)
        {
            if (Map != null && Map.Length > 0)
            {
                DrawBuffersEnum[] Mode = new DrawBuffersEnum[Map.Length];

                for (int i = 0; i < Map.Length; i++)
                {
                    Mode[i] = DrawBuffersEnum.ColorAttachment0 + Map[i];
                }

                GL.DrawBuffers(Mode.Length, Mode);
            }
            else
            {
                GL.DrawBuffer(DrawBufferMode.ColorAttachment0);
            }
        }
コード例 #31
0
        public void CreateMaps(float time)
        {
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            mapFBO.Activate();

            waterMapShader.Activate();
            waterMapShader.Uniform("time", time);
            waterMapShader.Uniform("numberOfWaves", numberOfWaves);
            int buffer = waterMapShader.GetResourceLocation(ShaderResourceType.RWBuffer, "WavesBuffer");

            waveBuffer.ActivateBind(buffer);

            //Activate Textures of FBO
            int textAmount = mapFBO.Textures.Count; //Number of Texture Channels of FBO

            for (int i = 0; i < textAmount; i++)
            {
                GL.ActiveTexture(TextureUnit.Texture0 + i);
                mapFBO.Textures[i].Activate();
            }

            DrawBuffersEnum[] buffers = new DrawBuffersEnum[textAmount];
            for (int i = 0; i < textAmount; i++)
            {
                buffers[i] = DrawBuffersEnum.ColorAttachment0 + i;
            }

            GL.DrawBuffers(textAmount, buffers);

            GL.DrawArrays(PrimitiveType.Quads, 0, 4);

            waveBuffer.Deactivate();

            for (int i = textAmount - 1; i >= 0; i--)
            {
                GL.ActiveTexture(TextureUnit.Texture0 + i);
                mapFBO.Textures[i].Deactivate();
            }

            waterMapShader.Deactivate();

            mapFBO.Deactivate();
        }
コード例 #32
0
        public void Begin(bool clear = true)
        {
            if (started)
            {
                throw new InvalidOperationException("Already started");
            }

            DrawState.FlushRenderer();
            if (!initialized)
            {
                initialize();
            }

            previousViewport = DrawState.Viewport;

            GL.GetInteger(GetPName.FramebufferBinding, out previousFrameBufferId);
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, frameBufferId);
            if (renderTextures.Length == 1)
            {
                GL.DrawBuffer(DrawBufferMode.ColorAttachment0);
            }
            else if (renderTextures.Length > 1)
            {
                var buffers = new DrawBuffersEnum[renderTextures.Length];
                for (int i = 0, size = renderTextures.Length; i < size; i++)
                {
                    Debug.Assert(DrawBuffersEnum.ColorAttachment0 + i <= DrawBuffersEnum.ColorAttachment15);
                    buffers[i] = DrawBuffersEnum.ColorAttachment0 + i;
                }
                GL.DrawBuffers(buffers.Length, buffers);
            }
            DrawState.CheckError("binding fbo");

            DrawState.Viewport = new Rectangle(0, 0, width, height);

            if (clear)
            {
                GL.ClearColor(0, 0, 0, 0);
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit);
            }

            started = true;
        }
コード例 #33
0
 private static void ApplyGLBind(NativeRenderTarget target)
 {
     if (target == null)
     {
         GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);
         GL.ReadBuffer(ReadBufferMode.Back);
         GL.DrawBuffer(DrawBufferMode.Back);
     }
     else
     {
         GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, target.samples > 0 ? target.handleMsaaFBO : target.handleMainFBO);
         DrawBuffersEnum[] buffers = new DrawBuffersEnum[target.targetInfos.Count];
         for (int i = 0; i < buffers.Length; i++)
         {
             buffers[i] = (DrawBuffersEnum)((int)DrawBuffersEnum.ColorAttachment0 + i);
         }
         GL.DrawBuffers(target.targetInfos.Count, buffers);
     }
 }
コード例 #34
0
ファイル: Canvas.cs プロジェクト: Aearnus/TISFAT-Zero
        private void Canvas_Load(object sender, EventArgs e)
        {
            glGraphics = GL_GRAPHICS;
            glGraphics.MakeCurrent();

            bkgColor = Color.White;

            //GLControl's load event is never fired, so we have to piggyback off the canvas's load function instead
            GLLoaded = true;

            //If you are going to be resizing the canvas later or changing the background color,
            //make sure to re-do these so the GLControl will work properly
            GL_HEIGHT = GL_GRAPHICS.Height;
            GL_WIDTH = GL_GRAPHICS.Width;
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            GL.Viewport(0, 0, GL_WIDTH, GL_HEIGHT);
            GL.Ortho(0, GL_WIDTH, 0, GL_HEIGHT, -1, 1);
            GL.ClearColor(bkgColor);

            //Since we are 2d, we don't need the depth test
            GL.Disable(EnableCap.DepthTest);

            #region Shader Initialization Stuff

            try
            {
                GL.GenFramebuffers(1, out OccluderFBO);
            }
            catch (Exception x)
            {
                Console.WriteLine("Shader Initialization failed! We can't have shaders.. :C");
                MessageBox.Show("Shader initialization failed with reason: " + x.Message + ", Sorry, but shadows have been disabled. Light object is still usable, but you won't be able to see the result on your machine.", "Shader problem!");
                Program.ToolboxForm.ckb_renderShadows.Enabled = false;
                ShadersCanLoad = false;
            }

            if (ShadersCanLoad)
            {
                Program.ToolboxForm.ckb_renderShadows.Enabled = true;

                //We need to generate a texture here so we can write what we're drawing to the FBO, and then we can sample it with a shader
                GL.GenTextures(1, out OccludersTexture);
                GL.BindTexture(TextureTarget.Texture2D, OccludersTexture);

                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);

                //make it the size of our lights
                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, (int)lightSize, (int)lightSize, 0, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);

                //This texture will be used with the shadowMap
                GL.GenTextures(1, out ShadowsTexture);
                GL.BindTexture(TextureTarget.Texture2D, ShadowsTexture);

                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
                //GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
                //GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);

                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, (int)lightSize, 1, 0, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);

                GL.BindTexture(TextureTarget.Texture2D, 0);

                //Generate a FBO for writing to the sampling texture

                // GL.GenFramebuffers(1, out OccluderFBO);
                //Moved to the beginning of the shader init

                GL.BindFramebuffer(FramebufferTarget.Framebuffer, OccluderFBO);
                GL.FramebufferTexture(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, OccludersTexture, 0);

                DrawBuffersEnum[] buf = new DrawBuffersEnum[1] { (DrawBuffersEnum)FramebufferAttachment.ColorAttachment0 };
                GL.DrawBuffers(buf.Length, buf);

                //and for our shadowMap, which is going to be 1xlightSize...

                GL.GenFramebuffers(1, out ShadowsFBO);

                GL.BindFramebuffer(FramebufferTarget.Framebuffer, ShadowsFBO);
                GL.FramebufferTexture(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, ShadowsTexture, 0);

                DrawBuffersEnum[] bufferEnum = new DrawBuffersEnum[1] { (DrawBuffersEnum)FramebufferAttachment.ColorAttachment0 };
                GL.DrawBuffers(bufferEnum.Length, bufferEnum);

                GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);

                //Create our shaders for drawing shadows
                Shader_pass = GL.CreateShader(ShaderType.VertexShader);
                Shader_shadowMap = GL.CreateShader(ShaderType.FragmentShader);
                Shader_shadowRender = GL.CreateShader(ShaderType.FragmentShader);

                Program_passAndMap = GL.CreateProgram();
                Program_passAndRender = GL.CreateProgram();

                //pass will fill in the needed variables that are not accessable in fragment shaders (but only in vertex shaders)
                //uniforms: u_projTrans
                GL.ShaderSource(Shader_pass, readShader("pass_vert.glsl"));
                GL.CompileShader(Shader_pass);

                int status;
                GL.GetShader(Shader_pass, ShaderParameter.CompileStatus, out status);

                if (status != 1)
                    Console.WriteLine("Shader_pass failed to compile:\n" + GL.GetShaderInfoLog(Shader_pass));

                //shadowMap will "map" the shadows onto a 1D texture
                //uniforms: u_texture, resolution
                GL.ShaderSource(Shader_shadowMap, readShader("shadowMap_frag.glsl"));
                GL.CompileShader(Shader_shadowMap);

                GL.GetShader(Shader_shadowMap, ShaderParameter.CompileStatus, out status);

                if (status != 1)
                    Console.WriteLine("Shader_shadowMap failed to compile:\n" + GL.GetShaderInfoLog(Shader_shadowMap));

                //and finally, shadowRender will take this map and render it onto the screen
                //uniforms: u_texture, resolution, softShadows
                GL.ShaderSource(Shader_shadowRender, readShader("shadowRender_frag.glsl"));
                GL.CompileShader(Shader_shadowRender);

                GL.GetShader(Shader_shadowRender, ShaderParameter.CompileStatus, out status);

                if (status != 1)
                    Console.WriteLine("Shader_shadowRender failed to compile:\n" + GL.GetShaderInfoLog(Shader_shadowRender));

                GL.AttachShader(Program_passAndMap, Shader_pass);
                GL.AttachShader(Program_passAndMap, Shader_shadowMap);

                GL.AttachShader(Program_passAndRender, Shader_pass);
                GL.AttachShader(Program_passAndRender, Shader_shadowRender);

                GL.LinkProgram(Program_passAndMap);
                GL.LinkProgram(Program_passAndRender);
            }
            #endregion

            Program.TimelineForm.addStickLayer("Stick Layer 1");
        }
コード例 #35
0
ファイル: FBO.cs プロジェクト: ayskbdyi/opengl4csharp
        /// <summary>
        /// Binds the framebuffer and all of the renderbuffers.
        /// Clears the buffer bits and sets viewport size.
        /// Perform all rendering after this call.
        /// </summary>
        /// <param name="clear">True to clear both the color and depth buffer bits of the FBO before enabling.</param>
        public void Enable(bool clear = true)
        {
            Gl.BindFramebuffer(FramebufferTarget.Framebuffer, BufferID);
            if (Attachments.Length == 1)
            {
                Gl.BindTexture(TextureTarget.Texture2D, TextureID[0]);
                Gl.FramebufferTexture(FramebufferTarget.Framebuffer, Attachments[0], TextureID[0], 0);
            }
            else
            {
                DrawBuffersEnum[] buffers = new DrawBuffersEnum[Attachments.Length];

                for (int i = 0; i < Attachments.Length; i++)
                {
                    Gl.BindTexture(TextureTarget.Texture2D, TextureID[i]);
                    Gl.FramebufferTexture(FramebufferTarget.Framebuffer, Attachments[i], TextureID[i], 0);
                    buffers[i] = (DrawBuffersEnum)Attachments[i];
                }

                Gl.BindTexture(TextureTarget.Texture2D, DepthID);
                Gl.FramebufferTexture(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, DepthID, 0);

                if (Attachments.Length > 1) Gl.DrawBuffers(Attachments.Length, buffers);
            }

            Gl.Viewport(0, 0, Size.Width, Size.Height);

            // configurably clear the buffer and color bits
            if (clear)
            {
                if (Attachments.Length == 1 && Attachments[0] == FramebufferAttachment.DepthAttachment)
                    Gl.Clear(ClearBufferMask.DepthBufferBit);
                else
                    Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            }
        }
コード例 #36
0
ファイル: FBOHandler.cs プロジェクト: Erlisch/Caliginous
        //Methods
        //-Public
        public static void CreateFBO(int width, int height)
        {
            //Change to AddFBO() if multiple FBOs are needed!
            DrawBuffersEnum[] dbe = new DrawBuffersEnum[] { DrawBuffersEnum.ColorAttachment0, DrawBuffersEnum.ColorAttachment1 };

            fBOID_I = GL.GenFramebuffer();
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, fBOID_I);

            //AddNewTextureToFBO(width, height);
            //currentTextureUsed_I = defaultTexture_I;
            AddNewTextureToFBO(width, height, FBOTextures.Color, FramebufferAttachment.ColorAttachment0);
            AddNewTextureToFBO(width, height, FBOTextures.Shadowmap, FramebufferAttachment.ColorAttachment1);

            if(GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer) != FramebufferErrorCode.FramebufferComplete) {
                System.Console.WriteLine("ERROR: Error creating FBO!");
                System.Console.WriteLine(GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer).ToString());
            }
            else { System.Console.WriteLine("FBO OK!"); }

            currentFBO_I = fBOID_I;

            GL.DrawBuffers(2, dbe);
        }
コード例 #37
0
		/// <summary>
		/// Binds a RenderTarget in order to use it.
		/// </summary>
		/// <param name="target">The RenderTarget to be bound.</param>
		public static void Bind(ContentRef<RenderTarget> target)
		{
			RenderTarget nextBound = target.IsExplicitNull ? null : target.Res;
			if (curBound == nextBound) return;

			if (curBound != null && nextBound != curBound)
			{
				// Blit multisampled fbo
				if (curBound.Samples > 0)
				{
					GL.Ext.BindFramebuffer(FramebufferTarget.ReadFramebuffer, curBound.glFboIdMSAA);
					GL.Ext.BindFramebuffer(FramebufferTarget.DrawFramebuffer, curBound.glFboId);
					for (int i = 0; i < curBound.targetInfo.Count; i++)
					{
						GL.ReadBuffer((ReadBufferMode)((int)ReadBufferMode.ColorAttachment0 + i));
						GL.DrawBuffer((DrawBufferMode)((int)DrawBufferMode.ColorAttachment0 + i));
						GL.Ext.BlitFramebuffer(
							0, 0, curBound.targetInfo[i].target.Res.TexelWidth, curBound.targetInfo[i].target.Res.TexelHeight,
							0, 0, curBound.targetInfo[i].target.Res.TexelWidth, curBound.targetInfo[i].target.Res.TexelHeight,
							ClearBufferMask.ColorBufferBit, (ExtFramebufferBlit)(int)BlitFramebufferFilter.Nearest);
					}
					GL.ReadBuffer(ReadBufferMode.Back);
					GL.DrawBuffer(DrawBufferMode.Back);
					GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);
				}

				// Generate Mipmaps for last bound
				for (int i = 0; i < curBound.targetInfo.Count; i++)
				{
					if (curBound.targetInfo[i].target.Res.HasMipmaps)
					{
						GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);

						int lastTexId;
						GL.GetInteger(GetPName.TextureBinding2D, out lastTexId);

						if (lastTexId != curBound.targetInfo[i].target.Res.OglTexId) 
							GL.BindTexture(TextureTarget.Texture2D, curBound.targetInfo[i].target.Res.OglTexId);

						GL.Ext.GenerateMipmap(GenerateMipmapTarget.Texture2D);

						if (lastTexId != curBound.targetInfo[i].target.Res.OglTexId) 
							GL.BindTexture(TextureTarget.Texture2D, lastTexId);
					}
				}
			}

			// Bind new RenderTarget
			if (nextBound == null)
			{
				curBound = null;
				GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);
				GL.DrawBuffer(DrawBufferMode.Back);
			}
			else
			{
				curBound = target.Res;
				GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, curBound.Samples > 0 ? curBound.glFboIdMSAA : curBound.glFboId);
				DrawBuffersEnum[] buffers = new DrawBuffersEnum[curBound.targetInfo.Count];
				for (int i = 0; i < buffers.Length; i++)
				{
					buffers[i] = (DrawBuffersEnum)((int)DrawBuffersEnum.ColorAttachment0 + i);
				}
				GL.DrawBuffers(curBound.targetInfo.Count, buffers);
			}
		}
コード例 #38
0
ファイル: BrushShader.cs プロジェクト: jpbruyere/Ottd3D
        public override void Update()
        {
            evenCycle = !evenCycle;

            GL.ActiveTexture (TextureUnit.Texture0);
            if (evenCycle) {
                drawBuffs = new DrawBuffersEnum[] {	DrawBuffersEnum.ColorAttachment1 };
                GL.BindTexture (TextureTarget.Texture2D, tex);
            } else {
                drawBuffs = new DrawBuffersEnum[] {	DrawBuffersEnum.ColorAttachment0 };
                GL.BindTexture (TextureTarget.Texture2D, evenTex);
            }

            base.Update ();
        }
コード例 #39
0
ファイル: FrameBuffer.cs プロジェクト: Lazzu/Hatzap
        public void Create()
        {
            Activate();

            DrawBuffersEnum[] list = new DrawBuffersEnum[targets.Count];

            // Attach textures to the framebuffer and set the type in the list
            for (int i = 0; i < targets.Count; i++)
            {
                GL.FramebufferTexture(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0 + i, targets[i].ID, 0);
                list[i] = DrawBuffersEnum.ColorAttachment0 + i;
            }

            if (UseDepthBuffer)
            {
                depthBuffer = GL.GenRenderbuffer();

                GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, depthBuffer);
                GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer,
                                       RenderbufferStorage.DepthComponent32,
                                       gameWindow.Width, gameWindow.Height);

                // Attach the depth buffer to the framebuffer
                GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer,
                                           FramebufferAttachment.DepthAttachment,
                                           RenderbufferTarget.Renderbuffer,
                                           depthBuffer);
            }

            // Set the list of draw buffers.
            GL.DrawBuffers(list.Length, list);

            // Get error code
            FramebufferErrorCode status = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer);

            // Check for errors
            if (status != FramebufferErrorCode.FramebufferComplete)
                throw new Exception("Error creating frame buffer! Status: " + status);

            Deactivate();

            vao = GL.GenVertexArray();
            int vbo = GL.GenBuffer();
            int ebo = GL.GenBuffer();

            GL.BindVertexArray(vao);
            GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, ebo);

            var vertices = new Vector3[] {
                new Vector3(-1, -1, 0),
                new Vector3(1, -1, 0),
                new Vector3(-1, 1, 0),
                new Vector3(1, 1, 0),
            };

            var indices = new int[] {
                0,1,2,
                1,3,2
            };

            GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(vertices.Length * Vector3.SizeInBytes), vertices, BufferUsageHint.StaticDraw);
            GL.BufferData(BufferTarget.ElementArrayBuffer, new IntPtr(indices.Length * sizeof(int)), indices, BufferUsageHint.StaticDraw);

            GL.EnableVertexAttribArray(0);
            GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, BlittableValueType.StrideOf(vertices), 0);

            GL.BindVertexArray(0);
        }
コード例 #40
0
        public int GetOpenGLHande(int handle, out DrawBuffersEnum[] drawBuffer)
        {
            int index, id;
            ExtractHandle(handle, out index, out id);

            if (id == -1 || Handles[index].Id != id || !Handles[index].Initialized)
            {
                drawBuffer = null;
                return 0;
            }

            drawBuffer = Handles[index].DrawBuffers;
            return Handles[index].FrameBufferObject;
        }
コード例 #41
0
ファイル: FBO.cs プロジェクト: remy22/opengl4csharp
        /// <summary>
        /// Binds the framebuffer and all of the renderbuffers.
        /// Clears the buffer bits and sets viewport size.
        /// Perform all rendering after this call.
        /// </summary>
        public void Enable()
        {
            DrawBuffersEnum[] buffers = new DrawBuffersEnum[Attachments.Length];

            Gl.BindFramebuffer(FramebufferTarget.Framebuffer, BufferID);
            for (int i = 0; i < Attachments.Length; i++)
            {
                Gl.BindTexture(TextureTarget.Texture2D, TextureID[i]);
                Gl.FramebufferTexture(FramebufferTarget.Framebuffer, Attachments[i], TextureID[i], 0);
                buffers[i] = (DrawBuffersEnum)Attachments[i];
            }
            if (Attachments.Length > 1) Gl.DrawBuffers(Attachments.Length, buffers);

            Gl.Viewport(0, 0, Size.Width, Size.Height);
            if (mipmaps) Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
        }
コード例 #42
0
ファイル: FrameBuffer.cs プロジェクト: AreonDev/NoWayOut
        public void UseAttachments(AttachmentUsage[] attachments)
        {
            if (!m_PrepareMode)
                GL.BindFramebuffer(FramebufferTarget.Framebuffer, ID);

            DrawBuffersEnum[] dbe = new DrawBuffersEnum[attachments.Length];
            for (int i = 0; i < dbe.Length; i++)
            {
                if (attachments[i] == AttachmentUsage.DepthStencil)
                    throw new ArgumentException();

                dbe[i] = (DrawBuffersEnum)attachments[i];
            }

            GL.DrawBuffers(attachments.Length, dbe);

            if(!m_PrepareMode)
                GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
        }