/// <summary>
 /// Creates and allocates a new
 /// texture with a OpenGL id.
 /// </summary>
 public Texture(TextureParamPack paramPack)
 {
     Id = GManager.GenTexture();
     Bind();
     ApplyParamPack(paramPack);
     Unbind();
 }
        public void ApplyParamPack(TextureParamPack texParams)
        {
            CheckBind();

            SetMinMag(texParams.MinFilter, texParams.MagFilter);
            SetWrapMode(texParams.WrapS, texParams.WrapT);
        }
Example #3
0
        public FramebufferTexture(int screenWidth, int screenHeight, TextureParamPack texParams,
                                  FramebufferAttachment attachmentType, PixelInternalFormat internalFormat, PixelFormat format, PixelType type)
            : base(texParams)
        {
            this.AttachmentType      = attachmentType;
            this.InternalPixelFormat = internalFormat;
            this.PixelFormat         = format;
            this.PixelType           = type;
            this.Width  = screenWidth;
            this.Height = screenHeight;

            CreateTexture();
        }
        public PostProcessBuffer(int width, int height)
            : base(width, height)
        {
            GLError.Begin();

            // Bind the FBO
            Bind();

            // Create the textures
            TextureParamPack texParams = new TextureParamPack(TextureMagFilter.Nearest, TextureMinFilter.Nearest, TextureWrapMode.ClampToEdge);

            ColorTexture = new FramebufferTexture(width, height, texParams, FramebufferAttachment.ColorAttachment0,
                                                  PixelInternalFormat.Rgba16f, PixelFormat.Rgba, PixelType.HalfFloat);

            // Create the depth buffer
            depthBuffer = GL.GenRenderbuffer();
            GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, depthBuffer);
            GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, RenderbufferStorage.DepthComponent24, Width, Height);
            GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment,
                                       RenderbufferTarget.Renderbuffer, depthBuffer);
            GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, 0);

            // Set and enable the draw buffers
            SetDrawBuffers(DrawBuffersEnum.ColorAttachment0);
            EnableDrawBuffers();

            // Check for errors
            CheckForErrors();

            // Unbind
            Unbind();

            ErrorCode err = GLError.End();

            if (err != ErrorCode.NoError)
            {
                throw new Exception(string.Format("Failed to create PostProcessBuffer. OpenGL Error: {0}", err));
            }
        }
        public TexRenderTarget(int width, int height)
            : base(width, height)
        {
            // Bind the FBO
            Bind();

            // Create the textures
            TextureParamPack texParams = new TextureParamPack(TextureMagFilter.Nearest, TextureMinFilter.Nearest, TextureWrapMode.ClampToEdge);

            Texture = new FramebufferTexture(width, height, texParams, FramebufferAttachment.ColorAttachment0,
                                             PixelInternalFormat.Rgba, PixelFormat.Rgba, PixelType.UnsignedByte);

            // Set and enable the draw buffers
            SetDrawBuffers(DrawBuffersEnum.ColorAttachment0);
            EnableDrawBuffers();

            // Check for errors
            CheckForErrors();

            // Unbind
            Unbind();
        }