public RenderTargetBinding(RenderTargetIdentifier[] colorRenderTargets, RenderBufferLoadAction[] colorLoadActions, RenderBufferStoreAction[] colorStoreActions, RenderTargetIdentifier depthRenderTarget, RenderBufferLoadAction depthLoadAction, RenderBufferStoreAction depthStoreAction)
 {
     this.m_ColorRenderTargets = colorRenderTargets;
     this.m_DepthRenderTarget  = depthRenderTarget;
     this.m_ColorLoadActions   = colorLoadActions;
     this.m_ColorStoreActions  = colorStoreActions;
     this.m_DepthLoadAction    = depthLoadAction;
     this.m_DepthStoreAction   = depthStoreAction;
     this.m_Flags = RenderTargetFlags.None;
 }
 public RenderTargetBinding(RenderTargetSetup setup)
 {
     this.m_ColorRenderTargets = new RenderTargetIdentifier[setup.color.Length];
     for (int i = 0; i < this.m_ColorRenderTargets.Length; i++)
     {
         this.m_ColorRenderTargets[i] = new RenderTargetIdentifier(setup.color[i], setup.mipLevel, setup.cubemapFace, setup.depthSlice);
     }
     this.m_DepthRenderTarget = setup.depth;
     this.m_ColorLoadActions  = (RenderBufferLoadAction[])setup.colorLoad.Clone();
     this.m_ColorStoreActions = (RenderBufferStoreAction[])setup.colorStore.Clone();
     this.m_DepthLoadAction   = setup.depthLoad;
     this.m_DepthStoreAction  = setup.depthStore;
     this.m_Flags             = RenderTargetFlags.None;
 }
Ejemplo n.º 3
0
        public unsafe RenderTarget(int width, int height, RenderTargetFlags flags,
                                   TextureWraps wrap = TextureWraps.Repeat, TextureFilters filter = TextureFilters.Nearest) :
            base(width, height)
        {
            fixed(uint *address = &framebufferId)
            {
                glGenFramebuffers(1, address);
            }

            glBindFramebuffer(GL_FRAMEBUFFER, framebufferId);

            uint id;

            glGenTextures(1, &id);
            glBindTexture(GL_TEXTURE_2D, id);
            Id = id;

            var isColorEnabled   = (flags & RenderTargetFlags.Color) > 0;
            var isDepthEnabled   = (flags & RenderTargetFlags.Depth) > 0;
            var isStencilEnabled = (flags & RenderTargetFlags.Stencil) > 0;

            uint texFormat;
            uint texType;
            uint texAttachment;

            if (isColorEnabled)
            {
                texFormat     = GL_RGBA;
                texType       = GL_UNSIGNED_BYTE;
                texAttachment = GL_COLOR_ATTACHMENT0;
            }
            else
            {
                texFormat     = GL_DEPTH_COMPONENT;
                texType       = GL_FLOAT;
                texAttachment = GL_DEPTH_ATTACHMENT;
            }

            glTexImage2D(GL_TEXTURE_2D, 0, (int)texFormat, (uint)width, (uint)height, 0, texFormat, texType, null);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (int)filter);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, (int)filter);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, (int)wrap);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, (int)wrap);
            glFramebufferTexture2D(GL_FRAMEBUFFER, texAttachment, GL_TEXTURE_2D, id, 0);

            if (!isColorEnabled)
            {
                glDrawBuffer(GL_NONE);
                glReadBuffer(GL_NONE);
            }
            else if (isDepthEnabled)
            {
                var format     = (uint)(isStencilEnabled ? GL_DEPTH24_STENCIL8 : GL_DEPTH_COMPONENT);
                var attachment = (uint)(isStencilEnabled ? GL_DEPTH_STENCIL_ATTACHMENT : GL_DEPTH_ATTACHMENT);

                fixed(uint *address = &renderbufferId)
                {
                    glGenRenderbuffers(1, address);
                }

                glBindRenderbuffer(GL_RENDERBUFFER, renderbufferId);
                glRenderbufferStorage(GL_RENDERBUFFER, format, (uint)width, (uint)height);
                glFramebufferRenderbuffer(GL_FRAMEBUFFER, attachment, GL_RENDERBUFFER, renderbufferId);
                glBindRenderbuffer(GL_RENDERBUFFER, 0);
            }

            if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
            {
                Debug.Fail("Error creating render target.");
            }

            glBindFramebuffer(GL_FRAMEBUFFER, 0);

            if (isColorEnabled)
            {
                clearBits |= GL_COLOR_BUFFER_BIT;
            }

            if (isDepthEnabled)
            {
                clearBits |= GL_DEPTH_BUFFER_BIT;
            }

            if (isStencilEnabled)
            {
                clearBits |= GL_STENCIL_BUFFER_BIT;
            }
        }
Ejemplo n.º 4
0
 public RenderTarget(ivec2 dimensions, RenderTargetFlags flags, TextureWraps wrap = TextureWraps.Repeat,
                     TextureFilters filter = TextureFilters.Nearest) :
     this(dimensions.x, dimensions.y, flags, wrap, filter)
 {
 }
Ejemplo n.º 5
0
        public unsafe RenderTarget(int width, int height, RenderTargetFlags flags) : base(width, height)
        {
            fixed(uint *address = &framebufferId)
            {
                glGenFramebuffers(1, address);
            }

            glBindFramebuffer(GL_FRAMEBUFFER, framebufferId);

            fixed(uint *address = &textureId)
            {
                glGenTextures(1, address);
            }

            glBindTexture(GL_TEXTURE_2D, textureId);
            Id = textureId;

            bool colorEnabled   = (flags & RenderTargetFlags.Color) > 0;
            bool depthEnabled   = (flags & RenderTargetFlags.Depth) > 0;
            bool stencilEnabled = (flags & RenderTargetFlags.Stencil) > 0;

            uint texFormat;
            uint texType;
            uint texAttachment;

            if (colorEnabled)
            {
                texFormat     = GL_RGBA;
                texType       = GL_UNSIGNED_BYTE;
                texAttachment = GL_COLOR_ATTACHMENT0;
            }
            else
            {
                texFormat     = GL_DEPTH_COMPONENT;
                texType       = GL_FLOAT;
                texAttachment = GL_DEPTH_ATTACHMENT;
            }

            glTexImage2D(GL_TEXTURE_2D, 0, (int)texFormat, (uint)width, (uint)height, 0, texFormat, texType, null);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
            glFramebufferTexture2D(GL_FRAMEBUFFER, texAttachment, GL_TEXTURE_2D, textureId, 0);

            if (!colorEnabled)
            {
                glDrawBuffer(GL_NONE);
                glReadBuffer(GL_NONE);
            }
            else if (depthEnabled)
            {
                uint format     = (uint)(stencilEnabled ? GL_DEPTH24_STENCIL8 : GL_DEPTH_COMPONENT);
                uint attachment = (uint)(stencilEnabled ? GL_DEPTH_STENCIL_ATTACHMENT : GL_DEPTH_ATTACHMENT);

                fixed(uint *address = &renderbufferId)
                {
                    glGenRenderbuffers(1, address);
                }

                glBindRenderbuffer(GL_RENDERBUFFER, renderbufferId);
                glRenderbufferStorage(GL_RENDERBUFFER, format, (uint)width, (uint)height);
                glFramebufferRenderbuffer(GL_FRAMEBUFFER, attachment, GL_RENDERBUFFER, renderbufferId);
                glBindRenderbuffer(GL_RENDERBUFFER, 0);
            }

            if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
            {
                throw new RenderTargetException("Error creating render target.");
            }

            glBindFramebuffer(GL_FRAMEBUFFER, 0);

            if (colorEnabled)
            {
                clearBits |= GL_COLOR_BUFFER_BIT;
            }

            if (depthEnabled)
            {
                clearBits |= GL_DEPTH_BUFFER_BIT;
            }

            if (stencilEnabled)
            {
                clearBits |= GL_STENCIL_BUFFER_BIT;
            }
        }
Ejemplo n.º 6
0
 public RenderTarget(ivec2 dimensions, RenderTargetFlags flags) : this(dimensions.x, dimensions.y, flags)
 {
 }