コード例 #1
0
        /// <summary>
        /// Attaches a <see cref="RenderbufferObject"/> to this <see cref="FramebufferObject"/> in a specified attachment point.
        /// </summary>
        /// <param name="renderbuffer">The <see cref="RenderbufferObject"/> to attach.</param>
        /// <param name="attachmentPoint">The attachment point to attach the <see cref="RenderbufferObject"/> to.</param>
        public void Attach(RenderbufferObject renderbuffer, FramebufferAttachmentPoint attachmentPoint)
        {
            if (renderbuffer == null)
            {
                throw new ArgumentNullException(nameof(renderbuffer));
            }

            ValidateAttachmentTypeExists(attachmentPoint);
            ValidateAttachmentTypeNotUsed(attachmentPoint);

            if (attachmentPoint == FramebufferAttachmentPoint.Depth && !renderbuffer.IsDepthOnly)
            {
                throw new InvalidFramebufferAttachmentException("When attaching a renderbuffer to a depth attachment point, the renderbuffer's format must be depth-only");
            }

            if (attachmentPoint == FramebufferAttachmentPoint.DepthStencil && !renderbuffer.IsDepthStencil)
            {
                throw new InvalidFramebufferAttachmentException("When attaching a renderbuffer to a depth-stencil attachment point, the renderbuffer's format must be depth-stencil");
            }

            if (attachmentPoint == FramebufferAttachmentPoint.Stencil && !renderbuffer.IsStencilOnly)
            {
                throw new InvalidFramebufferAttachmentException("When attaching a renderbuffer to a stencil attachment point, the renderbuffer's format must be stencil-only");
            }

            if (TrippyUtils.IsFramebufferAttachmentPointColor(attachmentPoint) && !renderbuffer.IsColorRenderableFormat)
            {
                throw new InvalidFramebufferAttachmentException("When attaching a renderbuffer to a color attachment point, the renderbuffer's format must be color-renderable");
            }

            GraphicsDevice.Framebuffer = this;
            GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, (FramebufferAttachment)attachmentPoint, RenderbufferTarget.Renderbuffer, renderbuffer.Handle);
            renderbufferAttachments.Add(new FramebufferRenderbufferAttachment(renderbuffer, attachmentPoint));
        }
コード例 #2
0
 private static void ValidateAttachmentTypeExists(FramebufferAttachmentPoint attachment)
 {
     if (!Enum.IsDefined(typeof(FramebufferAttachmentPoint), attachment))
     {
         throw new FormatException("Invalid attachment point");
     }
 }
コード例 #3
0
 /// <summary>
 /// Detaches whatever is in an attachment point.
 /// Throws an exception if there is no such attachment.
 /// </summary>
 /// <param name="attachmentPoint">The attachment point to clear.</param>
 public void Detach(FramebufferAttachmentPoint attachmentPoint)
 {
     if (!TryDetachTexture(attachmentPoint, out _))
     {
         if (!TryDetachRenderbuffer(attachmentPoint, out _))
         {
             throw new InvalidOperationException("The specified attachment point is empty");
         }
     }
 }
コード例 #4
0
        /// <summary>
        /// Gets a <see cref="RenderbufferObject"/> attachment from this <see cref="FramebufferObject"/>.
        /// </summary>
        /// <param name="attachmentPoint">The point to look for a renderbuffer attachment at.</param>
        /// <param name="attachment">The attachment found.</param>
        /// <returns>Whether a renderbuffer attachment was found at the specified attachment point.</returns>
        public bool TryGetRenderbufferAttachment(FramebufferAttachmentPoint attachmentPoint, out FramebufferRenderbufferAttachment attachment)
        {
            for (int i = 0; i < renderbufferAttachments.Count; i++)
            {
                if (renderbufferAttachments[i].AttachmentPoint == attachmentPoint)
                {
                    attachment = renderbufferAttachments[i];
                    return(true);
                }
            }

            attachment = default;
            return(false);
        }
コード例 #5
0
        /// <summary>
        /// Gets a <see cref="Texture"/> attachment from this <see cref="FramebufferObject"/>.
        /// </summary>
        /// <param name="attachmentPoint">The point to look for a texture attachment at.</param>
        /// <param name="attachment">The attachment found.</param>
        /// <returns>Whether a texture attachment was found at the specified attachment point.</returns>
        public bool TryGetTextureAttachment(FramebufferAttachmentPoint attachmentPoint, out FramebufferTextureAttachment attachment)
        {
            for (int i = 0; i < textureAttachments.Count; i++)
            {
                if (textureAttachments[i].AttachmentPoint == attachmentPoint)
                {
                    attachment = textureAttachments[i];
                    return(true);
                }
            }

            attachment = default;
            return(false);
        }
コード例 #6
0
ファイル: Framebuffer.cs プロジェクト: Zulkir/ObjectGL
        public void AttachRenderbuffer(FramebufferAttachmentPoint attachmentPoint, IRenderbuffer renderbuffer)
        {
            var newDesc = new FramebufferAttachmentDescription
            {
                Type = FramebufferAttachmentType.Renderbufer,
                Renderbuffer = renderbuffer,
            };

            if (IsRedundant(attachmentPoint, ref newDesc))
                return;
            var framebufferTarget = context.Bindings.Framebuffers.EditingTarget;
            context.Bindings.Framebuffers.ByTarget(framebufferTarget).Set(this);
            GL.FramebufferRenderbuffer((int)framebufferTarget, (int)attachmentPoint, (int)RenderbufferTarget.Renderbuffer, renderbuffer.Handle);
            UpdateStoredDescription(attachmentPoint, ref newDesc);
        }
コード例 #7
0
        /// <summary>
        /// Tries to detach a <see cref="RenderbufferObject"/> attached to the specified point.
        /// </summary>
        /// <param name="point">The attachment point to check.</param>
        /// <param name="attachment">The detached <see cref="RenderbufferObject"/> attachment, if the method returned true.</param>
        /// <returns>Returns whether the operation succeded.</returns>
        public bool TryDetachRenderbuffer(FramebufferAttachmentPoint point, out FramebufferRenderbufferAttachment attachment)
        {
            for (int i = 0; i < renderbufferAttachments.Count; i++)
            {
                if (renderbufferAttachments[i].AttachmentPoint == point)
                {
                    GraphicsDevice.Framebuffer = this;
                    GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, (FramebufferAttachment)point, RenderbufferTarget.Renderbuffer, 0);
                    attachment = renderbufferAttachments[i];
                    renderbufferAttachments.RemoveAt(i);
                    return(true);
                }
            }

            attachment = default;
            return(false);
        }
コード例 #8
0
        /// <summary>
        /// Tries to detach a <see cref="Texture"/> attached to the specified attachment point.
        /// </summary>
        /// <param name="point">The attachment point to check.</param>
        /// <param name="attachment">The detached <see cref="Texture"/> attachment, if the method returned true.</param>
        /// <returns>Returns whether the operation succeeded.</returns>
        public bool TryDetachTexture(FramebufferAttachmentPoint point, out FramebufferTextureAttachment attachment)
        {
            for (int i = 0; i < textureAttachments.Count; i++)
            {
                if (textureAttachments[i].AttachmentPoint == point)
                {
                    GraphicsDevice.Framebuffer = this;
                    GL.FramebufferTexture(FramebufferTarget.Framebuffer, (FramebufferAttachment)point, 0, 0);
                    attachment = textureAttachments[i];
                    textureAttachments.RemoveAt(i);
                    return(true);
                }
            }

            attachment = default;
            return(false);
        }
コード例 #9
0
        /// <summary>
        /// Attaches a <see cref="Texture"/> to this <see cref="FramebufferObject"/> in a specified attachment point.
        /// </summary>
        /// <param name="texture">The <see cref="Texture"/> to attach.</param>
        /// <param name="attachmentPoint">The attachment point to attach the <see cref="Texture"/> to.</param>
        public void Attach(Texture texture, FramebufferAttachmentPoint attachmentPoint)
        {
            if (texture == null)
            {
                throw new ArgumentNullException(nameof(texture));
            }

            ValidateAttachmentTypeExists(attachmentPoint);
            ValidateAttachmentTypeNotUsed(attachmentPoint);

            if (attachmentPoint == FramebufferAttachmentPoint.Depth && !TrippyUtils.IsImageFormatDepthOnly(texture.ImageFormat))
            {
                throw new InvalidFramebufferAttachmentException("When attaching a texture to a depth attachment point, the texture's format must be depth-only");
            }

            if (attachmentPoint == FramebufferAttachmentPoint.DepthStencil && !TrippyUtils.IsImageFormatDepthStencil(texture.ImageFormat))
            {
                throw new InvalidFramebufferAttachmentException("When attaching a texture to a depth-stencil attachment point, the texture's format must be depth-stencil");
            }

            if (attachmentPoint == FramebufferAttachmentPoint.Stencil && !TrippyUtils.IsImageFormatStencilOnly(texture.ImageFormat))
            {
                throw new InvalidFramebufferAttachmentException("When attaching a texture to a stencil attachment point, the texture's format must be stencil-only");
            }

            if (TrippyUtils.IsFramebufferAttachmentPointColor(attachmentPoint) && !TrippyUtils.IsImageFormatColorRenderable(texture.ImageFormat))
            {
                throw new InvalidFramebufferAttachmentException("When attaching a texture to a color attachment point, the texture's format must be color-renderable");
            }

            GraphicsDevice.Framebuffer = this;
            if (texture is Texture1D)
            {
                GL.FramebufferTexture1D(FramebufferTarget.Framebuffer, (FramebufferAttachment)attachmentPoint, texture.TextureType, texture.Handle, 0);
            }
            else if (texture is Texture2D)
            {
                GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, (FramebufferAttachment)attachmentPoint, texture.TextureType, texture.Handle, 0);
            }
            else
            {
                throw new InvalidFramebufferAttachmentException("This texture type cannot be attached to a framebuffer");
            }
            textureAttachments.Add(new FramebufferTextureAttachment(texture, attachmentPoint));
        }
コード例 #10
0
ファイル: Framebuffer.cs プロジェクト: Zulkir/ClarityWorlds
        public void AttachRenderbuffer(FramebufferAttachmentPoint attachmentPoint, IRenderbuffer renderbuffer)
        {
            var newDesc = new FramebufferAttachmentDescription
            {
                Type         = FramebufferAttachmentType.Renderbufer,
                Renderbuffer = renderbuffer,
            };

            if (IsRedundant(attachmentPoint, ref newDesc))
            {
                return;
            }
            var framebufferTarget = context.Bindings.Framebuffers.EditingTarget;

            context.Bindings.Framebuffers.ByTarget(framebufferTarget).Set(this);
            GL.FramebufferRenderbuffer((int)framebufferTarget, (int)attachmentPoint, (int)RenderbufferTarget.Renderbuffer, renderbuffer.Handle);
            UpdateStoredDescription(attachmentPoint, ref newDesc);
        }
コード例 #11
0
        /// <summary>
        /// Returns whether the specified attachment point is in use.
        /// </summary>
        /// <param name="attachmentType">The attachment point to check.</param>
        public bool HasAttachment(FramebufferAttachmentPoint attachmentType)
        {
            for (int i = 0; i < textureAttachments.Count; i++)
            {
                if (textureAttachments[i].AttachmentPoint == attachmentType)
                {
                    return(true);
                }
            }

            for (int i = 0; i < renderbufferAttachments.Count; i++)
            {
                if (renderbufferAttachments[i].AttachmentPoint == attachmentType)
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #12
0
ファイル: Framebuffer.cs プロジェクト: Zulkir/ClarityWorlds
 private void UpdateStoredDescription(FramebufferAttachmentPoint attachmentPoint, ref FramebufferAttachmentDescription newDesc)
 {
     if ((FramebufferAttachmentPoint.Color0 <= attachmentPoint && attachmentPoint <= FramebufferAttachmentPoint.Color15))
     {
         int index = attachmentPoint - FramebufferAttachmentPoint.Color0;
         colorAttachments[index] = newDesc;
         if (index >= enabledColorAttachmentsRange)
         {
             enabledColorAttachmentsRange = index + 1;
         }
     }
     else if (attachmentPoint == FramebufferAttachmentPoint.DepthStencil || attachmentPoint == FramebufferAttachmentPoint.Depth)
     {
         depthAttachment = newDesc;
     }
     else if (attachmentPoint == FramebufferAttachmentPoint.DepthStencil || attachmentPoint == FramebufferAttachmentPoint.Stencil)
     {
         stencilAttachment = newDesc;
     }
 }
コード例 #13
0
ファイル: Framebuffer.cs プロジェクト: Zulkir/ClarityWorlds
        public void AttachTextureAsLayeredImage(FramebufferAttachmentPoint attachmentPoint, ITexture2DMultisampleArray texture)
        {
            var newDesc = new FramebufferAttachmentDescription
            {
                Type          = FramebufferAttachmentType.TextureLayers,
                TextureTarget = TextureTarget.Texture2DMultisampleArray,
                Texture       = texture
            };

            if (IsRedundant(attachmentPoint, ref newDesc))
            {
                return;
            }
            var framebufferTarget = context.Bindings.Framebuffers.EditingTarget;

            context.Bindings.Framebuffers.ByTarget(framebufferTarget).Set(this);
            //gl.FramebufferTexture((int)framebufferTarget, (int)attachmentPoint, texture.Handle, 0);
            GL.FramebufferTexture2D((int)framebufferTarget, (int)attachmentPoint, (int)texture.Target, texture.Handle, 0);
            UpdateStoredDescription(attachmentPoint, ref newDesc);
        }
コード例 #14
0
ファイル: Framebuffer.cs プロジェクト: Zulkir/ClarityWorlds
        public void AttachTextureImage(FramebufferAttachmentPoint attachmentPoint, ITexture3D texture, int level, int depthLayer)
        {
            var newDesc = new FramebufferAttachmentDescription
            {
                Type          = FramebufferAttachmentType.Texture,
                TextureTarget = TextureTarget.Texture3D,
                Texture       = texture,
                Level         = level,
                Layer         = depthLayer
            };

            if (IsRedundant(attachmentPoint, ref newDesc))
            {
                return;
            }
            var framebufferTarget = context.Bindings.Framebuffers.EditingTarget;

            context.Bindings.Framebuffers.ByTarget(framebufferTarget).Set(this);
            GL.FramebufferTextureLayer((int)framebufferTarget, (int)attachmentPoint, texture.Handle, level, depthLayer);
            UpdateStoredDescription(attachmentPoint, ref newDesc);
        }
コード例 #15
0
ファイル: Framebuffer.cs プロジェクト: Zulkir/ClarityWorlds
        public void AttachTextureImage(FramebufferAttachmentPoint attachmentPoint, ITextureCubemap texture, int level, CubemapFace cubemapFace)
        {
            var newDesc = new FramebufferAttachmentDescription
            {
                Type          = FramebufferAttachmentType.Texture,
                TextureTarget = TextureTarget.TextureCubeMap,
                Texture       = texture,
                Level         = level,
                Layer         = cubemapFace - CubemapFace.PositiveX
            };

            if (IsRedundant(attachmentPoint, ref newDesc))
            {
                return;
            }
            var framebufferTarget = context.Bindings.Framebuffers.EditingTarget;

            context.Bindings.Framebuffers.ByTarget(framebufferTarget).Set(this);
            GL.FramebufferTexture2D((int)framebufferTarget, (int)attachmentPoint, (int)cubemapFace, texture.Handle, level);
            UpdateStoredDescription(attachmentPoint, ref newDesc);
        }
コード例 #16
0
ファイル: Framebuffer.cs プロジェクト: Zulkir/ClarityWorlds
        public void AttachTextureAsLayeredImage(FramebufferAttachmentPoint attachmentPoint, ITextureCubemap texture, int level)
        {
            var newDesc = new FramebufferAttachmentDescription
            {
                Type          = FramebufferAttachmentType.TextureLayers,
                TextureTarget = TextureTarget.TextureCubeMap,
                Texture       = texture,
                Level         = level
            };

            if (IsRedundant(attachmentPoint, ref newDesc))
            {
                return;
            }
            var framebufferTarget = context.Bindings.Framebuffers.EditingTarget;

            context.Bindings.Framebuffers.ByTarget(framebufferTarget).Set(this);
            //gl.FramebufferTexture(ft, fa, d.Texture.Handle, d.Level);
            GL.FramebufferTexture2D((int)framebufferTarget, (int)attachmentPoint, (int)texture.Target, texture.Handle, level);
            UpdateStoredDescription(attachmentPoint, ref newDesc);
        }
コード例 #17
0
ファイル: Framebuffer.cs プロジェクト: Zulkir/ClarityWorlds
        private bool IsRedundant(FramebufferAttachmentPoint attachmentPoint, ref FramebufferAttachmentDescription newDesc)
        {
            switch (attachmentPoint)
            {
            case FramebufferAttachmentPoint.Color0:
            case FramebufferAttachmentPoint.Color1:
            case FramebufferAttachmentPoint.Color2:
            case FramebufferAttachmentPoint.Color3:
            case FramebufferAttachmentPoint.Color4:
            case FramebufferAttachmentPoint.Color5:
            case FramebufferAttachmentPoint.Color6:
            case FramebufferAttachmentPoint.Color7:
            case FramebufferAttachmentPoint.Color8:
            case FramebufferAttachmentPoint.Color9:
            case FramebufferAttachmentPoint.Color10:
            case FramebufferAttachmentPoint.Color11:
            case FramebufferAttachmentPoint.Color12:
            case FramebufferAttachmentPoint.Color13:
            case FramebufferAttachmentPoint.Color14:
            case FramebufferAttachmentPoint.Color15:
                return(FramebufferAttachmentDescription.Equals(ref newDesc, ref colorAttachments[attachmentPoint - FramebufferAttachmentPoint.Color0]));

            case FramebufferAttachmentPoint.DepthStencil:
                return(FramebufferAttachmentDescription.Equals(ref newDesc, ref depthAttachment) &&
                       FramebufferAttachmentDescription.Equals(ref newDesc, ref stencilAttachment));

            case FramebufferAttachmentPoint.Depth:
                return(FramebufferAttachmentDescription.Equals(ref newDesc, ref depthAttachment));

            case FramebufferAttachmentPoint.Stencil:
                return(FramebufferAttachmentDescription.Equals(ref newDesc, ref stencilAttachment));

            default:
                throw new ArgumentOutOfRangeException("attachmentPoint");
            }
        }
コード例 #18
0
ファイル: Framebuffer.cs プロジェクト: Zulkir/ObjectGL
        public void AttachTextureAsLayeredImage(FramebufferAttachmentPoint attachmentPoint, ITextureCubemapArray texture, int level)
        {
            var newDesc = new FramebufferAttachmentDescription
            {
                Type = FramebufferAttachmentType.TextureLayers,
                TextureTarget = TextureTarget.TextureCubeMapArray,
                Texture = texture,
                Level = level
            };

            if (IsRedundant(attachmentPoint, ref newDesc))
                return;
            var framebufferTarget = context.Bindings.Framebuffers.EditingTarget;
            context.Bindings.Framebuffers.ByTarget(framebufferTarget).Set(this);
            //gl.FramebufferTexture(ft, fa, d.Texture.Handle, d.Level);
            GL.FramebufferTexture2D((int)framebufferTarget, (int)attachmentPoint, (int)texture.Target, texture.Handle, level);
            UpdateStoredDescription(attachmentPoint, ref newDesc);
        }
コード例 #19
0
ファイル: Framebuffer.cs プロジェクト: Zulkir/ObjectGL
        public void AttachTextureImage(FramebufferAttachmentPoint attachmentPoint, ITexture3D texture, int level, int depthLayer)
        {
            var newDesc = new FramebufferAttachmentDescription
            {
                Type = FramebufferAttachmentType.Texture,
                TextureTarget = TextureTarget.Texture3D,
                Texture = texture,
                Level = level,
                Layer = depthLayer
            };

            if (IsRedundant(attachmentPoint, ref newDesc))
                return;
            var framebufferTarget = context.Bindings.Framebuffers.EditingTarget;
            context.Bindings.Framebuffers.ByTarget(framebufferTarget).Set(this);
            GL.FramebufferTextureLayer((int)framebufferTarget, (int)attachmentPoint, texture.Handle, level, depthLayer);
            UpdateStoredDescription(attachmentPoint, ref newDesc);
        }
コード例 #20
0
ファイル: Framebuffer.cs プロジェクト: Zulkir/ClarityWorlds
        public void Detach(FramebufferAttachmentPoint attachmentPoint)
        {
            #region Check redundancy
            if ((FramebufferAttachmentPoint.Color0 <= attachmentPoint && attachmentPoint <= FramebufferAttachmentPoint.Color15))
            {
                if (colorAttachments[attachmentPoint - FramebufferAttachmentPoint.Color0].Type == FramebufferAttachmentType.Disabled)
                {
                    return;
                }
            }
            else if (attachmentPoint == FramebufferAttachmentPoint.DepthStencil)
            {
                if (depthAttachment.Type == FramebufferAttachmentType.Disabled &&
                    stencilAttachment.Type == FramebufferAttachmentType.Disabled)
                {
                    return;
                }
            }
            else if (attachmentPoint == FramebufferAttachmentPoint.Depth)
            {
                if (depthAttachment.Type == FramebufferAttachmentType.Disabled)
                {
                    return;
                }
            }
            else if (attachmentPoint == FramebufferAttachmentPoint.Stencil)
            {
                if (stencilAttachment.Type == FramebufferAttachmentType.Disabled)
                {
                    return;
                }
            }
            else
            {
                throw new ArgumentOutOfRangeException("attachmentPoint");
            }
            #endregion

            var framebufferTarget = context.Bindings.Framebuffers.EditingTarget;
            context.Bindings.Framebuffers.ByTarget(framebufferTarget).Set(this);
            GL.FramebufferTexture2D((int)framebufferTarget, (int)attachmentPoint, (int)TextureTarget.Texture2D, 0, 0);

            #region Update stored description
            if ((FramebufferAttachmentPoint.Color0 <= attachmentPoint && attachmentPoint <= FramebufferAttachmentPoint.Color15))
            {
                int index = attachmentPoint - FramebufferAttachmentPoint.Color0;
                colorAttachments[index].Type = FramebufferAttachmentType.Disabled;
                while (enabledColorAttachmentsRange > 0 && colorAttachments[enabledColorAttachmentsRange - 1].Type == FramebufferAttachmentType.Disabled)
                {
                    enabledColorAttachmentsRange--;
                }
            }
            else if (attachmentPoint == FramebufferAttachmentPoint.DepthStencil || attachmentPoint == FramebufferAttachmentPoint.Depth)
            {
                depthAttachment.Type = FramebufferAttachmentType.Disabled;
            }
            else if (attachmentPoint == FramebufferAttachmentPoint.DepthStencil || attachmentPoint == FramebufferAttachmentPoint.Stencil)
            {
                stencilAttachment.Type = FramebufferAttachmentType.Disabled;
            }
            #endregion
        }
コード例 #21
0
ファイル: Framebuffer.cs プロジェクト: Zulkir/ObjectGL
        public void Detach(FramebufferAttachmentPoint attachmentPoint)
        {
            #region Check redundancy
            if ((FramebufferAttachmentPoint.Color0 <= attachmentPoint && attachmentPoint <= FramebufferAttachmentPoint.Color15))
            {
                if (colorAttachments[attachmentPoint - FramebufferAttachmentPoint.Color0].Type == FramebufferAttachmentType.Disabled) return;
            }
            else if (attachmentPoint == FramebufferAttachmentPoint.DepthStencil)
            {
                if (depthAttachment.Type == FramebufferAttachmentType.Disabled &&
                    stencilAttachment.Type == FramebufferAttachmentType.Disabled)
                    return;
            }
            else if (attachmentPoint == FramebufferAttachmentPoint.Depth)
            {
                if (depthAttachment.Type == FramebufferAttachmentType.Disabled) return;
            }
            else if (attachmentPoint == FramebufferAttachmentPoint.Stencil)
            {
                if (stencilAttachment.Type == FramebufferAttachmentType.Disabled) return;
            }
            else
            {
                throw new ArgumentOutOfRangeException("attachmentPoint");
            }
            #endregion

            var framebufferTarget = context.Bindings.Framebuffers.EditingTarget;
            context.Bindings.Framebuffers.ByTarget(framebufferTarget).Set(this);
            GL.FramebufferTexture2D((int)framebufferTarget, (int)attachmentPoint, (int)TextureTarget.Texture2D, 0, 0);

            #region Update stored description
            if ((FramebufferAttachmentPoint.Color0 <= attachmentPoint && attachmentPoint <= FramebufferAttachmentPoint.Color15))
            {
                int index = attachmentPoint - FramebufferAttachmentPoint.Color0;
                colorAttachments[index].Type = FramebufferAttachmentType.Disabled;
                while (enabledColorAttachmentsRange > 0 && colorAttachments[enabledColorAttachmentsRange - 1].Type == FramebufferAttachmentType.Disabled)
                {
                    enabledColorAttachmentsRange--;
                }
            }
            else if (attachmentPoint == FramebufferAttachmentPoint.DepthStencil || attachmentPoint == FramebufferAttachmentPoint.Depth)
            {
                depthAttachment.Type = FramebufferAttachmentType.Disabled;
            }
            else if (attachmentPoint == FramebufferAttachmentPoint.DepthStencil || attachmentPoint == FramebufferAttachmentPoint.Stencil)
            {
                stencilAttachment.Type = FramebufferAttachmentType.Disabled;
            }
            #endregion
        }
コード例 #22
0
ファイル: Framebuffer.cs プロジェクト: Zulkir/ObjectGL
        public void AttachTextureImage(FramebufferAttachmentPoint attachmentPoint, ITextureCubemapArray texture, int level, int arrayIndex, CubemapFace cubemapFace)
        {
            var layer = 6 * arrayIndex + cubemapFace - CubemapFace.PositiveX;
            var newDesc = new FramebufferAttachmentDescription
            {
                Type = FramebufferAttachmentType.Texture,
                TextureTarget = TextureTarget.TextureCubeMapArray,
                Texture = texture,
                Level = level,
                Layer = layer
            };

            if (IsRedundant(attachmentPoint, ref newDesc))
                return;
            var framebufferTarget = context.Bindings.Framebuffers.EditingTarget;
            context.Bindings.Framebuffers.ByTarget(framebufferTarget).Set(this);
            GL.FramebufferTextureLayer((int)framebufferTarget, (int)attachmentPoint, texture.Handle, layer, level);
            UpdateStoredDescription(attachmentPoint, ref newDesc);
        }
コード例 #23
0
ファイル: Framebuffer.cs プロジェクト: Zulkir/ObjectGL
        private void UpdateStoredDescription(FramebufferAttachmentPoint attachmentPoint, ref FramebufferAttachmentDescription newDesc)
        {
            if ((FramebufferAttachmentPoint.Color0 <= attachmentPoint && attachmentPoint <= FramebufferAttachmentPoint.Color15))
            {
                int index = attachmentPoint - FramebufferAttachmentPoint.Color0;
                colorAttachments[index] = newDesc;
                if (index >= enabledColorAttachmentsRange)
                    enabledColorAttachmentsRange = index + 1;

            }
            else if (attachmentPoint == FramebufferAttachmentPoint.DepthStencil || attachmentPoint == FramebufferAttachmentPoint.Depth)
            {
                depthAttachment = newDesc;
            }
            else if (attachmentPoint == FramebufferAttachmentPoint.DepthStencil || attachmentPoint == FramebufferAttachmentPoint.Stencil)
            {
                stencilAttachment = newDesc;
            }
        }
コード例 #24
0
ファイル: Framebuffer.cs プロジェクト: Zulkir/ObjectGL
 private bool IsRedundant(FramebufferAttachmentPoint attachmentPoint, ref FramebufferAttachmentDescription newDesc)
 {
     switch (attachmentPoint)
     {
         case FramebufferAttachmentPoint.Color0:
         case FramebufferAttachmentPoint.Color1:
         case FramebufferAttachmentPoint.Color2:
         case FramebufferAttachmentPoint.Color3:
         case FramebufferAttachmentPoint.Color4:
         case FramebufferAttachmentPoint.Color5:
         case FramebufferAttachmentPoint.Color6:
         case FramebufferAttachmentPoint.Color7:
         case FramebufferAttachmentPoint.Color8:
         case FramebufferAttachmentPoint.Color9:
         case FramebufferAttachmentPoint.Color10:
         case FramebufferAttachmentPoint.Color11:
         case FramebufferAttachmentPoint.Color12:
         case FramebufferAttachmentPoint.Color13:
         case FramebufferAttachmentPoint.Color14:
         case FramebufferAttachmentPoint.Color15:
             return FramebufferAttachmentDescription.Equals(ref newDesc, ref colorAttachments[attachmentPoint - FramebufferAttachmentPoint.Color0]);
         case FramebufferAttachmentPoint.DepthStencil:
             return FramebufferAttachmentDescription.Equals(ref newDesc, ref depthAttachment) &&
                    FramebufferAttachmentDescription.Equals(ref newDesc, ref stencilAttachment);
         case FramebufferAttachmentPoint.Depth:
             return FramebufferAttachmentDescription.Equals(ref newDesc, ref depthAttachment);
         case FramebufferAttachmentPoint.Stencil:
             return FramebufferAttachmentDescription.Equals(ref newDesc, ref stencilAttachment);
         default:
             throw new ArgumentOutOfRangeException("attachmentPoint");
     }
 }
コード例 #25
0
ファイル: TrippyUtils.cs プロジェクト: xiaoxiongnpu/TrippyGL
        /// <summary>
        /// Returns whether the specified <see cref="FramebufferAttachmentPoint"/> represents a color[i] attachment.
        /// </summary>
        public static bool IsFramebufferAttachmentPointColor(FramebufferAttachmentPoint attachment)
        {
            int i = attachment - FramebufferAttachmentPoint.Color0;

            return(i >= 0 && i < 32);
        }
コード例 #26
0
 /// <summary>
 /// Creates a <see cref="FramebufferRenderbufferAttachment"/>.
 /// </summary>
 /// <param name="renderbuffer">The <see cref="RenderbufferObject"/> to attach in this attachment.</param>
 /// <param name="attachmentPoint">The attachment point to which this attachment attaches to.</param>
 public FramebufferRenderbufferAttachment(RenderbufferObject renderbuffer, FramebufferAttachmentPoint attachmentPoint)
 {
     Renderbuffer    = renderbuffer;
     AttachmentPoint = attachmentPoint;
 }
コード例 #27
0
 /// <summary>
 /// Creates a <see cref="FramebufferTextureAttachment"/>.
 /// </summary>
 /// <param name="texture">The <see cref="Texture"/> to attach in this attachment.</param>
 /// <param name="attachmentPoint">The attachment point to which this attachment attaches to.</param>
 public FramebufferTextureAttachment(Texture texture, FramebufferAttachmentPoint attachmentPoint)
 {
     Texture         = texture;
     AttachmentPoint = attachmentPoint;
 }
コード例 #28
0
ファイル: Framebuffer.cs プロジェクト: Zulkir/ObjectGL
        public void AttachTextureImage(FramebufferAttachmentPoint attachmentPoint, ITexture2DMultisample texture)
        {
            var newDesc = new FramebufferAttachmentDescription
            {
                Type = FramebufferAttachmentType.Texture,
                TextureTarget = TextureTarget.Texture2DMultisample,
                Texture = texture
            };

            if (IsRedundant(attachmentPoint, ref newDesc))
                return;
            var framebufferTarget = context.Bindings.Framebuffers.EditingTarget;
            context.Bindings.Framebuffers.ByTarget(framebufferTarget).Set(this);
            //gl.FramebufferTexture((int)framebufferTarget, (int)attachmentPoint, texture.Handle, 0);
            GL.FramebufferTexture2D((int)framebufferTarget, (int)attachmentPoint, (int)texture.Target, texture.Handle, 0);
            UpdateStoredDescription(attachmentPoint, ref newDesc);
        }
コード例 #29
0
 private void ValidateAttachmentTypeNotUsed(FramebufferAttachmentPoint attachment)
 {
     if (HasAttachment(attachment))
         throw new InvalidOperationException("The " + nameof(FramebufferObject) + " already has this type of attachment"); }