Ejemplo n.º 1
0
        public void SetRenderBuffer(FramebufferAttachment attachment, RenderBuffer buffer)
        {
            GL.BindFramebuffer(FramebufferType.Framebuffer, framebuffer);
            GL.FramebufferRenderbuffer(FramebufferType.Framebuffer, attachment, RenderbufferType.Renderbuffer, buffer == null ? 0 : buffer.Handle);

            if (attachment == FramebufferAttachment.DepthAttachment)
            {
                buffers[16] = buffer;
            }
            else if (attachment == FramebufferAttachment.StencilAttachment)
            {
                buffers[17] = buffer;
            }
            else
            {
                int idx = attachment - FramebufferAttachment.Color0;
                buffers[idx] = buffer;
                if (buffer == null)
                {
                    attachments &= ~(1 << idx);
                }
                else
                {
                    attachments |= 1 << idx;
                }
            }
        }
Ejemplo n.º 2
0
 public void AddRenderbuffer(FramebufferAttachment attachment, RenderbufferStorage storage, int width, int height)
 {
     using (Scope ())
     {
         var rb = GL.GenRenderbuffer ();
         GL.BindRenderbuffer (RenderbufferTarget.Renderbuffer, rb);
         GL.RenderbufferStorage (RenderbufferTarget.Renderbuffer, storage, width, height);
         GL.FramebufferRenderbuffer (_target, attachment, RenderbufferTarget.Renderbuffer, rb);
         CheckStatus ();
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a framebuffer object and its associated resources (depth and pbuffers).
        /// </summary>
        /// <param name="Size">Specifies the size (in pixels) of the framebuffer and it's associated buffers.</param>
        /// <param name="Attachments">Specifies the attachments to use for the pbuffers.</param>
        /// <param name="Format">Specifies the internal pixel format for the pbuffers.</param>
        public FBO(Size Size, FramebufferAttachment[] Attachments, PixelInternalFormat Format, bool Mipmaps)
        {
            this.Size = Size;
            this.Attachments = Attachments;
            this.Format = Format;
            this.mipmaps = Mipmaps;

            // First create the framebuffer
            BufferID = Gl.GenFramebuffer();
            Gl.BindFramebuffer(FramebufferTarget.Framebuffer, BufferID);

            // Create and attach a 24-bit depth buffer to the framebuffer
            DepthID = Gl.GenRenderbuffer();
            Gl.BindRenderbuffer(RenderbufferTarget.Renderbuffer, DepthID);
            Gl.RenderbufferStorage(RenderbufferTarget.Renderbuffer, RenderbufferStorage.DepthComponent24, Size.Width, Size.Height);

            // Create n texture buffers (known by the number of attachments)
            TextureID = new uint[Attachments.Length];
            Gl.GenTextures(Attachments.Length, TextureID);

            // Bind the n texture buffers to the framebuffer
            for (int i = 0; i < Attachments.Length; i++)
            {
                Gl.BindTexture(TextureTarget.Texture2D, TextureID[i]);
                Gl.TexImage2D(TextureTarget.Texture2D, 0, Format, Size.Width, Size.Height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);
                if (Mipmaps)
                {
                    Gl.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, 9729); // public const int GL_LINEAR = 9729;
                    Gl.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, 9987); // public const int GL_LINEAR_MIPMAP_LINEAR = 9987;
                    Gl.GenerateMipmap(GenerateMipmapTarget.Texture2D);
                }
                Gl.FramebufferTexture(FramebufferTarget.Framebuffer, Attachments[i], TextureID[i], 0);
            }

            // Build the framebuffer and check for errors
            Gl.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, RenderbufferTarget.Renderbuffer, DepthID);

            FramebufferErrorCode status = Gl.CheckFramebufferStatus(FramebufferTarget.Framebuffer);
            if (status != FramebufferErrorCode.FramebufferComplete)
            {
                Console.WriteLine("Frame buffer did not compile correctly.  Returned {0}, glError: {1}", status.ToString(), Gl.GetError().ToString());
            }

            Gl.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
        }
Ejemplo n.º 4
0
        private void ChangeTextureAttachment(FramebufferAttachment attachment, TextureTarget textureTarget, 
			int glTexture)
        {
            using (Scope ())
            {
                switch (textureTarget)
                {
                    case TextureTarget.Texture1D:
                        GL.FramebufferTexture1D (_target, attachment, textureTarget, glTexture, 0);
                        break;
                    case TextureTarget.Texture2D:
                        GL.FramebufferTexture2D (_target, attachment, textureTarget, glTexture, 0);
                        break;
                    default:
                        GL.FramebufferTexture (_target, attachment, glTexture, 0);
                        break;
                }
                if (glTexture != 0)
                    CheckStatus ();
            }
        }
Ejemplo n.º 5
0
        protected void AttachTexture(FramebufferAttachment attachmentTarget, TextureBase texture)
        {
            Bind(FramebufferTarget.Framebuffer);

            if (texture == null)
            {
                GL.FramebufferTexture(FramebufferTarget.Framebuffer, attachmentTarget, 0, 0);
                Debug.Assert(AttachedTextures.ContainsKey(attachmentTarget));
                AttachedTextures.Remove(attachmentTarget);
                return;
            }

            Debug.Assert(
                AttachedTextures.All(pair => pair.Value.Size == texture.Size),
                "All render target sizes for a framebuffer object must be equal.");
            Size = texture.Size;

            texture.Bind();

            GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, attachmentTarget, texture.Target, texture.Handle, 0);
            AttachedTextures[attachmentTarget] = texture;
        }
Ejemplo n.º 6
0
        /*public static void AddNewTextureToFBO(int width, int height, FramebufferAttachment fa = FramebufferAttachment.ColorAttachment1) {
            if(defaultTexture_I == -1) {
                defaultTexture_I = TextureHandler.CreateTexture(width, height); //Save this somewhere??? (We currently have no need to change it out...)
                if(defaultTexture_I > -1) {
                    //GL.FramebufferTexture(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, currentTextureUsed_I, 0);
                    GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, fa, TextureTarget.Texture2D, defaultTexture_I, 0);

                    if(GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer) != FramebufferErrorCode.FramebufferComplete) {
                        System.Console.WriteLine("ERROR: Error attaching to FBO!");
                        System.Console.WriteLine(GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer).ToString());
                    }
                    else { System.Console.WriteLine("FBO attachment OK!"); }
                }
            }
        }*/
        public static void AddNewTextureToFBO(int width, int height, FBOTextures ft = FBOTextures.New, FramebufferAttachment fa = FramebufferAttachment.ColorAttachment0)
        {
            if(ft == FBOTextures.New) {
                //IMPLEMENTERA!?!
            }
            else if(ft == FBOTextures.Color) {
                if(colorTexture_I == -1) { colorTexture_I = TextureHandler.CreateTexture(width, height); }
                if(colorTexture_I > -1) {
                    GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, fa, TextureTarget.Texture2D, colorTexture_I, 0);
                }
            }
            else if(ft == FBOTextures.Shadowmap) {
                if(shadowmapTexture_I == -1) { shadowmapTexture_I = TextureHandler.CreateTexture(width, height); }
                if(shadowmapTexture_I > -1) {
                    GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, fa, TextureTarget.Texture2D, shadowmapTexture_I, 0);
                }
            }

            if(GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer) != FramebufferErrorCode.FramebufferComplete) {
                System.Console.WriteLine("ERROR: Error attaching to FBO!");
                System.Console.WriteLine(GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer).ToString());
            }
            else { System.Console.WriteLine("FBO attachment OK!"); }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Draws the shader in its current state to a frame buffer (and associated texture). Useful for precomputation.
 /// </summary>
 public void Draw2DFrame(FramebufferTarget Framebuffer, FramebufferAttachment Attachment, uint Texture, int Width, int Height)
 {
     GL.FramebufferTexture2D(Framebuffer, Attachment, TextureTarget.Texture2D, Texture, 0);
     GL.Viewport(0, 0, Width, Height);
     this.DrawFull();
 }
Ejemplo n.º 8
0
 public void AttachTextureLayer(FramebufferAttachment attachment, int level, int layer)
 {
     textures[attachment].Apply();
     // \todo
 }
Ejemplo n.º 9
0
 public partial void FramebufferTextureMultiview([Flow(FlowDirection.In)] FramebufferTarget target, [Flow(FlowDirection.In)] FramebufferAttachment attachment, [Flow(FlowDirection.In)] uint texture, [Flow(FlowDirection.In)] int level, [Flow(FlowDirection.In)] int baseViewIndex, [Flow(FlowDirection.In)] uint numViews);
Ejemplo n.º 10
0
 /// <summary>
 /// Creates a framebuffer object and its associated resources (depth and pbuffers).
 /// </summary>
 /// <param name="Size">Specifies the size (in pixels) of the framebuffer and it's associated buffers.</param>
 /// <param name="Attachments">Specifies the attachment to use for the pbuffer.</param>
 /// <param name="Format">Specifies the internal pixel format for the pbuffer.</param>
 public FBO(Size Size, FramebufferAttachment Attachment = FramebufferAttachment.ColorAttachment0, PixelInternalFormat Format = PixelInternalFormat.Rgba8, bool Mipmaps = true)
     : this(Size, new FramebufferAttachment[] { Attachment }, Format, Mipmaps)
 {
 }
 public void FramebufferRenderbuffer(
     FramebufferTarget target, FramebufferAttachment attachment, RenderbufferTarget renderbuffertarget, int renderbuffer)
 {
     GL.FramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer);
 }
Ejemplo n.º 12
0
		public override void AttachTexture2D(FramebufferAttachment attachmentPoint, int textureId)
		{
			throw new System.InvalidOperationException();
		}
Ejemplo n.º 13
0
 /// <summary>
 /// Attaches the given texture level to the an attachment point.
 /// </summary>
 /// <remarks>
 /// If texture is a three-dimensional, cube map array, cube map, one- or two-dimensional array, or two-dimensional multisample array texture
 /// the specified texture level is an array of images and the framebuffer attachment is considered to be layered.
 /// </remarks>
 /// <param name="target">The framebuffer target to bind to.</param>
 /// <param name="attachment">The attachment point to attach to.</param>
 /// <param name="texture">The texture to attach.</param>
 /// <param name="level">The level of the texture to attach.</param>
 public void Attach(FramebufferTarget target, FramebufferAttachment attachment, Texture texture, int level = 0)
 {
     texture.AssertLevel(level);
     AssertActive(target);
     GL.FramebufferTexture(target, attachment, texture.Handle, level);
     CheckState(target);
 }
Ejemplo n.º 14
0
 public TextureBase this[FramebufferAttachment index]
 {
     get { return AttachedTextures[index]; }
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Detaches the currently attached render buffer from the given attachment point.
 /// </summary>
 /// <param name="target">The framebuffer target to bind to.</param>
 /// <param name="attachment">The attachment point to detach from.</param>
 public void DetachRenderbuffer(FramebufferTarget target, FramebufferAttachment attachment)
 {
     AssertActive(target);
     GL.FramebufferRenderbuffer(target, attachment, RenderbufferTarget.Renderbuffer, 0);
     CheckState(target);
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Detaches the currently attached texture from the given attachment point.
 /// </summary>
 /// <param name="attachment">The attachment point to detach from.</param>
 /// <param name="target">The framebuffer target to bind to.</param>
 public void DetachTexture(FramebufferTarget target, FramebufferAttachment attachment)
 {
     AssertActive(target);
     GL.FramebufferTexture(target, attachment, 0, 0);
     CheckState(target);
 }
Ejemplo n.º 17
0
 public unsafe static void NamedFramebufferTexture(uint framebuffer, FramebufferAttachment attachment, uint texture, int level)
 => glNamedFramebufferTexture(framebuffer, attachment, texture, level);
Ejemplo n.º 18
0
 public abstract void FramebufferTexture2DMultisample([Flow(FlowDirection.In)] FramebufferTarget target, [Flow(FlowDirection.In)] FramebufferAttachment attachment, [Flow(FlowDirection.In)] TextureTarget textarget, [Flow(FlowDirection.In)] uint texture, [Flow(FlowDirection.In)] int level, [Flow(FlowDirection.In)] uint samples);
Ejemplo n.º 19
0
 public static void FramebufferTexture2DMultisampleEXT(FramebufferTarget target, FramebufferAttachment attachment, TextureTarget textarget, UInt32 texture, Int32 level, Int32 samples)
 {
     Debug.Assert(Delegates.pglFramebufferTexture2DMultisampleEXT != null, "pglFramebufferTexture2DMultisampleEXT not implemented");
     Delegates.pglFramebufferTexture2DMultisampleEXT((Int32)target, (Int32)attachment, (Int32)textarget, texture, level, samples);
     LogCommand("glFramebufferTexture2DMultisampleEXT", null, target, attachment, textarget, texture, level, samples);
     DebugCheckErrors(null);
 }
Ejemplo n.º 20
0
 public static void GetFramebufferAttachmentParameter(FramebufferTarget target, FramebufferAttachment attachment, FramebufferParameterName pname, out int @params)
 {
   if (GraphicsExtensions.UseArbFramebuffer)
     GL.GetFramebufferAttachmentParameter(target, attachment, pname, out @params);
   else
     GL.Ext.GetFramebufferAttachmentParameter(target, attachment, pname, out @params);
 }
Ejemplo n.º 21
0
 public static void UnbindTextureFromFBO(FramebufferAttachment fa = FramebufferAttachment.ColorAttachment0)
 {
     GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, fa, TextureTarget.Texture2D, 0, 0);
     //currentTextureUsed_I = 0;
 }
Ejemplo n.º 22
0
 internal static void Attach(FramebufferAttachment attachPoint, Texture2D texture)
 {
     if (texture != null)
     {
         // TODO:  Mipmap level
         Texture2DGL3x textureGL = (Texture2DGL3x)texture;
         GL.FramebufferTexture(FramebufferTarget.Framebuffer, attachPoint, textureGL.Handle.Value, 0);
     }
     else
     {
         GL.FramebufferTexture(FramebufferTarget.Framebuffer, attachPoint, 0, 0);
     }
 }
Ejemplo n.º 23
0
 public void BindRenderBuffer(RenderBuffer RBuffer, FramebufferAttachment Attachment)
 {
     //GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, Attachment, RenderbufferTarget.Renderbuffer, RBuffer.ID);
     GL.NamedFramebufferRenderbuffer(ID, Attachment, RenderbufferTarget.Renderbuffer, RBuffer.ID);
 }
Ejemplo n.º 24
0
 public static void AttachExistingTextureToFBO(int textureID, FramebufferAttachment fa = FramebufferAttachment.ColorAttachment0)
 {
     if(textureID > -1) { //Ändra till GL.IsTexture() ???
         GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, fa, TextureTarget.Texture2D, textureID, 0);
     }
 }
Ejemplo n.º 25
0
 //don't do this either
 public override void attachTarget(FramebufferAttachment attachTarget, Texture target)
 {
     throw new Exception("Cannot bind a target to the default frame buffer");
 }
Ejemplo n.º 26
0
		public virtual void AttachRenderbuffer(FramebufferAttachment attachmentPoint, int renderbufferId)
		{
			_validated = false;
			GL.BindFramebuffer(FramebufferTarget.FramebufferExt, FramebufferId);
			GL.Ext.FramebufferRenderbuffer(FramebufferTarget.FramebufferExt, FramebufferAttachment.DepthAttachmentExt, RenderbufferTarget.RenderbufferExt, renderbufferId);
		}
Ejemplo n.º 27
0
 public void SetTextureCubeMap(FramebufferAttachment attachment, TextureTarget face, int miplevel, TextureCubeMap texture)
 {
     GL.BindFramebuffer(FramebufferType.Framebuffer, framebuffer);
     GL.FramebufferTexture2D(FramebufferType.Framebuffer, attachment, face, texture == null ? 0 : texture.Handle, miplevel);
     SetTextureAttachment(attachment, texture);
 }
Ejemplo n.º 28
0
		public override void AttachRenderbuffer(FramebufferAttachment attachmentPoint, int renderbufferId)
		{
			throw new System.InvalidOperationException();
		}
Ejemplo n.º 29
0
 public void BindTexture(Texture2D Tex, FramebufferAttachment Attachment)
 {
     //GL.FramebufferTexture(FramebufferTarget.Framebuffer, Attachment, Tex.ID, 0);
     GL.NamedFramebufferTexture(ID, Attachment, Tex.ID, 0);
 }
Ejemplo n.º 30
0
		public virtual void AttachTexture2D(FramebufferAttachment attachmentPoint, int textureId)
		{
			_validated = false;
			GL.BindFramebuffer(FramebufferTarget.FramebufferExt, FramebufferId);
			GL.FramebufferTexture2D(FramebufferTarget.FramebufferExt, attachmentPoint, TextureTarget.Texture2D, textureId, 0);
		}
Ejemplo n.º 31
0
        public FrameBufferColorMRT(int num, int w, int h, TextureFormat format = TextureFormat.Normal)
        {
            IW  = w;
            IH  = h;
            FBO = GL.GenFramebuffer();
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, FBO);
            for (int i = 0; i < num; i++)
            {
                Targets.Add(new Texture2D(w, h, false, format));
            }
            //BB = new Texture2D(w, h, false, format);
            DB = new TextureDepth(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);
            DrawBuffersEnum[] drawb = new DrawBuffersEnum[num];
            for (int i = 0; i < num; i++)
            {
                FramebufferAttachment fa = FramebufferAttachment.ColorAttachment0;
                switch (i)
                {
                case 0:
                    fa       = FramebufferAttachment.ColorAttachment0;
                    drawb[0] = DrawBuffersEnum.ColorAttachment0;
                    break;

                case 1:
                    fa       = FramebufferAttachment.ColorAttachment1;
                    drawb[1] = DrawBuffersEnum.ColorAttachment1;
                    break;

                case 2:
                    fa       = FramebufferAttachment.ColorAttachment2;
                    drawb[2] = DrawBuffersEnum.ColorAttachment2;
                    break;

                case 3:
                    fa       = FramebufferAttachment.ColorAttachment3;
                    drawb[3] = DrawBuffersEnum.ColorAttachment3;
                    break;

                case 4:
                    fa       = FramebufferAttachment.ColorAttachment4;
                    drawb[4] = DrawBuffersEnum.ColorAttachment4;
                    break;

                case 5:
                    fa       = FramebufferAttachment.ColorAttachment5;
                    drawb[5] = DrawBuffersEnum.ColorAttachment5;
                    break;

                case 6:
                    fa       = FramebufferAttachment.ColorAttachment6;
                    drawb[6] = DrawBuffersEnum.ColorAttachment6;
                    break;

                case 7:
                    fa       = FramebufferAttachment.ColorAttachment7;
                    drawb[7] = DrawBuffersEnum.ColorAttachment7;
                    break;
                }

                GL.FramebufferTexture(FramebufferTarget.Framebuffer, fa, Targets[i].ID, 0);
            }

            //  DrawBuffersEnum db = DrawBuffersEnum.ColorAttachment0;

            GL.DrawBuffers(drawb.Length, drawb);

            if (GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer) != FramebufferErrorCode.FramebufferComplete)
            {
                Console.WriteLine("Framebuffer failure.");
            }
            Console.WriteLine("Framebuffer success.");
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
            GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, 0);
        }
Ejemplo n.º 32
0
 public void SetTexture3D(FramebufferAttachment attachment, int miplevel, int zOffset, Texture3D texture)
 {
     GL.BindFramebuffer(FramebufferType.Framebuffer, framebuffer);
     GL.FramebufferTexture3D(FramebufferType.Framebuffer, attachment, TextureTarget.Texture3D, texture == null ? 0 : texture.Handle, miplevel, zOffset);
     SetTextureAttachment(attachment, texture);
 }
Ejemplo n.º 33
0
 public void AddTexture(FramebufferAttachment attachment, Texture texture)
 {
     using (texture.Scope ())
         ChangeTextureAttachment (attachment, texture._target, texture._glTexture);
 }
Ejemplo n.º 34
0
 void SetTextureAttachment(FramebufferAttachment attachment, Texture texture)
 {
     if (attachment == FramebufferAttachment.DepthAttachment)
     {
         textures[16] = texture;
     }
     else if (attachment == FramebufferAttachment.StencilAttachment)
     {
         textures[17] = texture;
     }
     else
     {
         int idx = attachment - FramebufferAttachment.Color0;
         textures[idx] = texture;
         if (texture == null)
         {
             attachments &= ~(1 << idx);
         }
         else
         {
             attachments |= 1 << idx;
         }
     }
 }
Ejemplo n.º 35
0
 public void RemoveTexture(FramebufferAttachment attachment, Texture texture)
 {
     ChangeTextureAttachment (attachment, texture._target, 0);
 }
Ejemplo n.º 36
0
 public FBO(int width, int height, FramebufferAttachment attachment = FramebufferAttachment.ColorAttachment0, PixelInternalFormat format = PixelInternalFormat.Rgba8, bool mipmaps = true)
     : this(new Size(width, height), new FramebufferAttachment[] { attachment }, format, mipmaps)
 {
 }
Ejemplo n.º 37
0
 public static void FramebufferTexture2D(FramebufferTarget target, FramebufferAttachment attachment, TextureTarget textarget, int texture, int level)
 {
   if (GraphicsExtensions.UseArbFramebuffer)
     GL.FramebufferTexture2D(target, attachment, textarget, texture, level);
   else
     GL.Ext.FramebufferTexture2D(target, attachment, textarget, texture, level);
 }
Ejemplo n.º 38
0
        /// <summary>
        /// Creates a framebuffer object and its associated resources (depth and pbuffers).
        /// </summary>
        /// <param name="Size">Specifies the size (in pixels) of the framebuffer and it's associated buffers.</param>
        /// <param name="Attachments">Specifies the attachments to use for the frame buffer.</param>
        /// <param name="Format">Specifies the internal pixel format for the frame buffer.</param>
        /// <param name="Mipmaps">Specified whether to build mipmaps after the frame buffer is unbound.</param>
        public FBO(Size Size, FramebufferAttachment[] Attachments, PixelInternalFormat Format, bool Mipmaps, TextureParameter filterType = TextureParameter.Linear)
        {
            this.Size = Size;
            this.Attachments = Attachments;
            this.Format = Format;
            this.mipmaps = Mipmaps;

            // First create the framebuffer
            BufferID = Gl.GenFramebuffer();
            Gl.BindFramebuffer(FramebufferTarget.Framebuffer, BufferID);

            if (Attachments.Length == 1 && Attachments[0] == FramebufferAttachment.DepthAttachment)
            {
                // if this is a depth attachment only
                TextureID = new uint[] { Gl.GenTexture() };
                Gl.BindTexture(TextureTarget.Texture2D, TextureID[0]);

                Gl.TexImage2D(TextureTarget.Texture2D, 0, Format, Size.Width, Size.Height, 0, PixelFormat.DepthComponent, PixelType.Float, IntPtr.Zero);
                Gl.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, TextureParameter.Nearest);
                Gl.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, TextureParameter.Nearest);
                Gl.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, TextureParameter.ClampToEdge);
                Gl.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, TextureParameter.ClampToEdge);

                Gl.FramebufferTexture(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, TextureID[0], 0);
                Gl.DrawBuffer(DrawBufferMode.None);
                Gl.ReadBuffer(ReadBufferMode.None);
            }
            else
            {
                // Create n texture buffers (known by the number of attachments)
                TextureID = new uint[Attachments.Length];
                Gl.GenTextures(Attachments.Length, TextureID);

                // Bind the n texture buffers to the framebuffer
                for (int i = 0; i < Attachments.Length; i++)
                {
                    Gl.BindTexture(TextureTarget.Texture2D, TextureID[i]);
                    Gl.TexImage2D(TextureTarget.Texture2D, 0, Format, Size.Width, Size.Height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);
                    if (Mipmaps)
                    {
                        Gl.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, TextureParameter.Linear);
                        Gl.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, TextureParameter.LinearMipMapLinear);
                        Gl.GenerateMipmap(GenerateMipmapTarget.Texture2D);
                    }
                    else
                    {
                        Gl.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, filterType);
                        Gl.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, filterType);
                    }
                    Gl.FramebufferTexture(FramebufferTarget.Framebuffer, Attachments[i], TextureID[i], 0);
                }

                // Create and attach a 24-bit depth buffer to the framebuffer
                DepthID = Gl.GenTexture();
                Gl.BindTexture(TextureTarget.Texture2D, DepthID);

                Gl.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Depth24Stencil8, Size.Width, Size.Height, 0, PixelFormat.DepthStencil, PixelType.UnsignedInt248, IntPtr.Zero);
                Gl.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, TextureParameter.Nearest);
                Gl.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, TextureParameter.Nearest);
                Gl.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, TextureParameter.ClampToEdge);
                Gl.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, TextureParameter.ClampToEdge);

                Gl.FramebufferTexture(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, DepthID, 0);
                Gl.FramebufferTexture(FramebufferTarget.Framebuffer, FramebufferAttachment.StencilAttachment, DepthID, 0);
            }

            // Build the framebuffer and check for errors
            FramebufferErrorCode status = Gl.CheckFramebufferStatus(FramebufferTarget.Framebuffer);
            if (status != FramebufferErrorCode.FramebufferComplete)
            {
                Console.WriteLine("Frame buffer did not compile correctly.  Returned {0}, glError: {1}", status.ToString(), Gl.GetError().ToString());
            }

            Gl.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
        }
Ejemplo n.º 39
0
 public static void FramebufferRenderbuffer(FramebufferTarget target, FramebufferAttachment attachment, RenderbufferTarget renderbuffertarget, uint renderbuffer)
 {
   if (GraphicsExtensions.UseArbFramebuffer)
     GL.FramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer);
   else
     GL.Ext.FramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer);
 }
Ejemplo n.º 40
0
 /// <summary>
 /// Draws the shader in its current state to a frame buffer (and associated texture). Useful for precomputation. The "Layer" uniform is set
 /// in the shader to indicate depth.
 /// </summary>
 public void Draw3DFrame(FramebufferTarget Framebuffer, FramebufferAttachment Attachment, uint Texture, int Width, int Height, int Depth)
 {
     this.Call();
     int luniform = GL.GetUniformLocation(this.Program, "Layer");
     for (int t = 0; t < Depth; t++)
     {
         GL.FramebufferTexture3D(Framebuffer, Attachment, TextureTarget.Texture3D, Texture, 0, t);
         GL.Viewport(0, 0, Width, Height);
         GL.Uniform1(luniform, t);
         DrawQuad();
     }
 }
Ejemplo n.º 41
0
 public Frame_Buffer(TextureUnit texNumber, FramebufferAttachment colournumber)
 {
     Create(texNumber, colournumber);
 }