Пример #1
0
        public static Framebuffer CreateFramebuffer(GraphicsDevice device, uint resolutionX, uint resolutionY, PixelFormat pixelFormat)
        {
            var drawTrgt = device.ResourceFactory.CreateTexture(
                new TextureDescription(resolutionX,
                                       resolutionY,
                                       1, 1, 1,
                                       pixelFormat,
                                       TextureUsage.RenderTarget | TextureUsage.Sampled | TextureUsage.Storage,
                                       TextureType.Texture2D)
                );

            var depthTrgt = device.ResourceFactory.CreateTexture(
                new TextureDescription(resolutionY,
                                       resolutionY,
                                       1, 1, 1,
                                       PixelFormat.R32_Float,
                                       TextureUsage.DepthStencil,
                                       TextureType.Texture2D)
                );

            FramebufferAttachmentDescription[] cltTrgs = new FramebufferAttachmentDescription[1]
            {
                new FramebufferAttachmentDescription()
                {
                    ArrayLayer = 0,
                    MipLevel   = 0,
                    Target     = drawTrgt
                }
            };

            FramebufferAttachmentDescription depTrg = new FramebufferAttachmentDescription()
            {
                ArrayLayer = 0,
                MipLevel   = 0,
                Target     = depthTrgt
            };

            var frameBuffDesc = new FramebufferDescription()
            {
                ColorTargets = cltTrgs,
                //DepthTarget = depTrg
            };
            var offscreenBuffer = device.ResourceFactory.CreateFramebuffer(frameBuffDesc);

            return(offscreenBuffer);
        }
Пример #2
0
        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;
            }
        }
Пример #3
0
        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);
        }
Пример #4
0
 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");
     }
 }
Пример #5
0
        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);
        }
Пример #6
0
        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);
        }
Пример #7
0
        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);
        }
Пример #8
0
        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);
        }