class EE::Graphics::FrameBuffer

Overview

A frame buffer allows rendering to a off-sreen 2D texture More…

#include <framebuffer.hpp>

class FrameBuffer {
public:
    // construction

    virtual ~FrameBuffer();

    // methods

    static FrameBuffer* New(
        const Uint32& Width,
        const Uint32& Height,
        bool StencilBuffer = true,
        bool DepthBuffer = false,
        bool useColorBuffer = false,
        const Uint32& channels = 4,
        EE::Window::Window* window = NULL
    );

    virtual void bind() = 0;
    virtual void unbind() = 0;
    virtual void draw(const Vector2f& position, const Sizef& size) = 0;
    virtual void draw(Rect src, Rect dst) = 0;
    void clear();
    virtual void reload() = 0;
    virtual void resize(const Uint32& Width, const Uint32& Height) = 0;
    virtual const Int32& getFrameBufferId() const = 0;
    Texture* getTexture() const;
    void setClearColor(const ColorAf& color);
    ColorAf getClearColor() const;
    const Int32& getWidth() const;
    const Int32& getHeight() const;
    const Sizei& getSize() const;
    const Sizef getSizef();
    const bool& hasColorBuffer() const;
    const bool& hasDepthBuffer() const;
    const bool& hasStencilBuffer() const;
    const std::string& getName() const;
    void setName(const std::string& name);
    const String::HashType& getId() const;
    virtual bool created() const = 0;
};

Detailed Documentation

A frame buffer allows rendering to a off-sreen 2D texture

Methods

static FrameBuffer* New(
    const Uint32& Width,
    const Uint32& Height,
    bool StencilBuffer = true,
    bool DepthBuffer = false,
    bool useColorBuffer = false,
    const Uint32& channels = 4,
    EE::Window::Window* window = NULL
)

Creates a new instance of a frame buffer.

Parameters:

Width

The frame buffer width

Height

The frame buffer height

StencilBuffer

Indicates if a stencil buffer is used

DepthBuffer

Indicates if a depth buffer is used

useColorBuffer

Indicates if the frame buffer uses a color attachment render buffer ( instead of a texture ) *

channels

Number of channels of the frame buffer to create

window

In case that the application is using more than one window, the user can indicate which one to use ( by default uses the current active window )

virtual void bind() = 0

Enables the off-screen rendering. From this moment any rendered primitive will be rendered to the frame buffer. Anything rendered since the frame buffer is binded will use the fram buffer coordinates, so position 0,0 means 0,0 point in the frame buffer, not the screen.

virtual void unbind() = 0

Disables the off-screen rendering. Anything rendered after this will be rendered to the back-buffer.

virtual void draw(const Vector2f& position, const Sizef& size) = 0

Draws the buffer to the screen

virtual void draw(Rect src, Rect dst) = 0

Draws the buffer to the screen

void clear()

Clears the frame buffer pixels to the default frame buffer clear color.

virtual void reload() = 0

Recreates the frame buffer ( delete the current and creates a new one ). This is needed by the engine to recover any context lost.

virtual void resize(const Uint32& Width, const Uint32& Height) = 0

Resizes the current Frame Buffer.

virtual const Int32& getFrameBufferId() const = 0

Returns:

The allocated Frame Buffer internal Id ( OpenGL FBO id )

Texture* getTexture() const

Returns:

The frame buffer texture. Everything is rendered to this texture. To render the frame buffer you just need to draw the texture as any other texture. The frame buffer must be unbinded before any rendering is done outside the frame buffer. For example MyFrameBufferPtr-> getTexture() ->Draw(0,0);

void setClearColor(const ColorAf& color)

Sets the frame buffer clear color.

ColorAf getClearColor() const

Returns:

The clear color used for the frame buffer.

const Int32& getWidth() const

Returns:

The frame buffer width.

const Int32& getHeight() const

Returns:

The frame buffer height.

const Sizei& getSize() const

Returns:

The frame buffer size.

const Sizef getSizef()

Returns:

The frame buffer size ( float ).

const bool& hasColorBuffer() const

Returns:

True if the frame buffer has a color buffer.

const bool& hasDepthBuffer() const

Returns:

True if the frame buffer has a depth buffer.

const bool& hasStencilBuffer() const

Returns:

True if the frame buffer has a stencil buffer

const std::string& getName() const

Returns:

The frame buffer name.

void setName(const std::string& name)

Set a name to the frame buffer

const String::HashType& getId() const

Returns:

The hash id from its name

virtual bool created() const = 0

Returns:

If the frame buffer was created