예제 #1
0
        //! On update window
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            if (this._disposedValue)
            {
                return;
            }

            int i_read  = (this._frame % 2) == 0 ? 1 : 0;
            int i_write = (this._frame % 2) == 0 ? 1 : 0;

            GL.Viewport(0, 0, this.Size.X, this.Size.Y);

            _fbo.Textures[0].BindImage(1, ITexture.Access.Write);

            float  margin        = 0.5f;
            Color4 color         = new Color4(0.5f, 1.0f, 0.25f, 1.0f);
            float  random_number = (float)_rand.Next(1000) / 1000.0f;

            GL.ProgramUniform4(this._compute_prog.Object, 1, color);
            GL.ProgramUniform1(this._compute_prog.Object, 2, margin);
            GL.ProgramUniform1(this._compute_prog.Object, 3, random_number);

            _compute_prog.Use();
            this._frame++;

            GL.DispatchCompute(1, 1, 1);
            //GL.MemoryBarrier(MemoryBarrierFlags.ShaderImageAccessBarrierBit); // alternative:  MemoryBarrierFlags.AllBarrierBits;
            GL.MemoryBarrier(MemoryBarrierFlags.AllBarrierBits);

            /* DEBUG output
             * var data_ptr = GL.MapNamedBufferRange(this._coord_ssbo.Object, IntPtr.Zero, 8, BufferAccessMask.MapReadBit);
             * float[] managedArray = new float[2];
             * Marshal.Copy(data_ptr, managedArray, 0, 2);
             * GL.UnmapNamedBuffer(this._coord_ssbo.Object);
             * Console.WriteLine("data x: " + managedArray[0].ToString() + " y: " + managedArray[1].ToString());
             */

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            // Be aware, this won't work if the target framebuffer is a multisampling framebuffer
            if (this.Size.X > this.Size.Y)
            {
                _fbo.Blit(null, (this.Size.X - this.Size.Y) / 2, 0, this.Size.Y, this.Size.Y, true);
            }
            else
            {
                _fbo.Blit(null, 0, (this.Size.Y - this.Size.X) / 2, this.Size.X, this.Size.X, true);
            }

            Context.SwapBuffers();
            base.OnUpdateFrame(e);
        }